• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:43
CEST 03:43
KST 10:43
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Ro4 Preview: Mirror Mirror4[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5[ASL22] Ro16 Preview: Rough Waters10
Community News
SC4ALL: II SC2 Complete Invited Player Lineup10StarCraft II 5.0.17 PTR Patch Notes (Sept 30, 2026)73Weekly Cups (Sept 21-27): herO and ByuN double2Weekly Cups (Sep 13-20): herO scores triple3BSL Season 2317
StarCraft 2
General
StarCraft II 5.0.17 PTR Patch Notes (Sept 30, 2026) SC4ALL: II SC2 Complete Invited Player Lineup How do you feel about the mass reverts in the 5.0.17 PTR? Back to SC2 after 14 years - Protoss CTRL groups? October World Ranking: herO stays #1, ByuN returns
Tourneys
Stellar Fest TWO the Moon (Dec 16-20) Sparkling Tuna Cup - Weekly Open Tournament 2026 GSTL Grand Finals Sea Duckling Open (Global, Bronze-Diamond) SC2 INu's Battles#21 [ 3-Days tournament ]
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
[M] (2) Sweltering Sands [M] (2) Frigid Storage
External Content
Mutation # 546 Catch the Train The PondCast: SC2 News & Results Mutation # 545 And Drops and Rifts Mutation # 544 Double Trouble
Brood War
General
20-year-old Valorant player starting StarCraft Sagi.gg Launcher Released Fantasy returning? BSL Season 23 Bot on ladder
Tourneys
[ASL22] Semifinal A [Megathread] Daily Proleagues [ASL22] Ro8 Day 4 2v2v2v2 Tournament
Strategy
Cliff Jump Revisited (1 in a 1000 strategy) Replay Review Process - What do you do? Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Warcraft III: The Frozen Throne Stormgate/Frost Giant Megathread Total Annihilation Zero
Dota 2
Dota 2 Champions League Season 3 Begins April 25! Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Artificial Intelligence Thread
Fan Clubs
Serral Fan Club
Media & Entertainment
Movie Discussion! [Manga] One Piece Diablo Animated Series on Netflix
Sports
Football (Soccer) Thread MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Recent Gifted Posts
Blogs
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Escaping Into Video Games: G…
TrAiDoS
38 yo Retired SWE loo…
PurE)Rabbit-SF
Can Bots Beat Pros?? Starcr…
namkraft
[meme] I finally understa…
LUCKY_NOOB
Regacy Esports:Our Goa…
regacyesports
Customize Sidebar...

Website Feedback

Closed Threads



Active: 9602 users

The Big Programming Thread - Page 791

Forum Index > General Forum
Post a Reply
Prev 1 789 790 791 792 793 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
RoomOfMush
Profile Joined March 2015
1296 Posts
Last Edited: 2016-11-03 20:31:23
November 03 2016 20:31 GMT
#15801
Yes, that is correct. The most basic binary search trees work like that. Of course you could come up with more complex tree implementations like AVL-trees and such.
findingthelimit
Profile Joined May 2012
Hong Kong219 Posts
November 03 2016 20:34 GMT
#15802
can anyone provide me some advice with learning android? I'm not interested in every aspect of it, but I do have a couple apps that I'd like to build. I've read the google developers guide, but I'm not sure whether that's the best way to approach learning. I'm thinking of checking out some repositories of existing apps, and understanding the lifecycle and working from there, but I struggle to know what the "standard" way of doing various things are. I know java, I can learn xml on my own, but I've never really built apps before, and only familiarized myself with basic MVC in college.

I found out just this morning that MVP, the architecture google seems to advocate, is actually somewhat outdated, and MVVM and redux (i have no idea what this is) has become more mainstream.
mantequilla
Profile Blog Joined June 2012
Turkey781 Posts
Last Edited: 2016-11-03 21:18:09
November 03 2016 21:17 GMT
#15803
If you don't know android, and apps you plan to build are not enterprise grade complex apps, I'd say don't care much about stuff like MVVM and just learn the core things first, like activity lifecycle, ui layout, stuff that runs in background threads etc.

in my opinion things like MVVM starts to become important when you are so advanced and above the usual stuff it doesn't satisfy your needs anymore, otherwise it's premature over engineering. never no harm in learning though.
Age of Mythology forever!
findingthelimit
Profile Joined May 2012
Hong Kong219 Posts
November 03 2016 21:36 GMT
#15804
On November 04 2016 06:17 mantequilla wrote:
If you don't know android, and apps you plan to build are not enterprise grade complex apps, I'd say don't care much about stuff like MVVM and just learn the core things first, like activity lifecycle, ui layout, stuff that runs in background threads etc.

in my opinion things like MVVM starts to become important when you are so advanced and above the usual stuff it doesn't satisfy your needs anymore, otherwise it's premature over engineering. never no harm in learning though.


well, i want to build a blackjack game, to start with. In non-android terminology, i'll likely need a controller (activity?), where i keep track of the game, and a service class (what's the equivalent?), where i invoke methods like drawing a card, calculating the value of the card, etc., because i'd prefer not to have a bunch of code cluttering up the activity class. However, I'm not sure whether a service class exists in android, so i looked at conventional architecture for aos.

I blabbered a bunch of (non)sense so you can have a grasp on what kind of beginner i am - do you have any advice as to where i should look to further my knowledge?

thanks for your help!
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-03 21:50:49
November 03 2016 21:50 GMT
#15805
ah yikes hard problem here near the end of my review

we have:


public class LinkedList<T extends Comparable<T>> {

private class Node {
private T data;
private Node next;

private Node(T data) {
this.data = data;
next = null;
}

}

private Node head;


public LinkedList() {
head = null;
}
}


The review wants me to:

// Define a constructor that takes a TreeSet<T> as a parameter
// and initializes a linked list with the elements in
// the set. The new list must be sorted in increasing lexicographic order.

We've never done anything like this
I am guessing I should use recursion

so my constructor might look like this:


LinkedList(TreeSet<T> tset) {
if(tset != null){
head = new Node(tset.first());
tsetToLinkedList(head, tset.first() );
}
}


and then I would make a helper method that looks like .... eh...


private void tsetToLinkedList(Node node, T tsetNode, TreeSet<T> tset) {
if(tset.higher(tsetNode) != null) {
node.next = new Node(tset.higher(tsetNode));
tsetToLinkedList(node.next, tset.higher(tsetNode), tset);
}
}


how does that look?
I'll test it if I need or get no feedback but that kind of sounds like a pain, lol
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-11-03 21:59:01
November 03 2016 21:53 GMT
#15806
I usually just Google for open-source projects related to what I'm doing, figure out how the state works for what I want to do, and then copy their implementation in what way I prefer doing.

I complained about this a lot of pages back but there's no actual "standard" way of doing things in Android. It's all whatever you learned and feel is better. For example some people use a global event bus, while the people I worked with created local event buses. Some people use callbacks instead of event buses. Some people use a single activity with views. Some people use a single activity and swap fragments. Some people use multiple activities. You try it, see if you like it, then you change or learn a newer thing.

Following fads is kinda a waste since they change all the time (re: http://zserge.com/blog/android-mvp-mvvm-redux-history.html). Should just make stuff work if you want to make stuff work, and follow the fads to learn new stuff if that's your jam.


All around useful Android tools though:

Gson
Retrofit
Event Bus
Picasso
Dagger
ButterKnife


On November 04 2016 06:36 findingthelimit wrote:
Show nested quote +
On November 04 2016 06:17 mantequilla wrote:
If you don't know android, and apps you plan to build are not enterprise grade complex apps, I'd say don't care much about stuff like MVVM and just learn the core things first, like activity lifecycle, ui layout, stuff that runs in background threads etc.

in my opinion things like MVVM starts to become important when you are so advanced and above the usual stuff it doesn't satisfy your needs anymore, otherwise it's premature over engineering. never no harm in learning though.


well, i want to build a blackjack game, to start with. In non-android terminology, i'll likely need a controller (activity?), where i keep track of the game, and a service class (what's the equivalent?), where i invoke methods like drawing a card, calculating the value of the card, etc., because i'd prefer not to have a bunch of code cluttering up the activity class. However, I'm not sure whether a service class exists in android, so i looked at conventional architecture for aos.

I blabbered a bunch of (non)sense so you can have a grasp on what kind of beginner i am - do you have any advice as to where i should look to further my knowledge?

thanks for your help!


okay that helps tell us where you are. well a Service in Android is a specific thing, more like long-running background thread. I think what you're referring to as a service is just a class that provides a set of actions. In which case just make a class that the Activity initializes and calls to get the deck and calls onClick with.
There is no one like you in the universe.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 03 2016 22:02 GMT
#15807
On November 04 2016 06:50 travis wrote:
Lexicographic

TreeSet doc
iterator()
Returns an iterator over the elements in this set in ascending order.

Lexicographical order just means smallest to largest. You have an iterator that provides the items in this order. You don't need recursion for that at all.
If you have a good reason to disagree with the above, please tell me. Thank you.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 03 2016 22:05 GMT
#15808
ok so if I do a for each to make each linked list node out of the treeset nodes, then how do I actually connect those nodes to form my linked list?
RoomOfMush
Profile Joined March 2015
1296 Posts
November 03 2016 22:09 GMT
#15809
On November 04 2016 07:02 spinesheath wrote:
Show nested quote +
On November 04 2016 06:50 travis wrote:
Lexicographic

TreeSet doc
Show nested quote +
iterator()
Returns an iterator over the elements in this set in ascending order.

Lexicographical order just means smallest to largest. You have an iterator that provides the items in this order. You don't need recursion for that at all.

I dont think travis is using the TreeSet from the standard library. They are writing their own LinkedList and the code he showed had methods called on the TreeSet which dont exist in the standard library.
But of course only travis can tell us what kind of TreeSet he is using.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
November 03 2016 22:14 GMT
#15810
On November 04 2016 07:09 RoomOfMush wrote:
Show nested quote +
On November 04 2016 07:02 spinesheath wrote:
On November 04 2016 06:50 travis wrote:
Lexicographic

TreeSet doc
iterator()
Returns an iterator over the elements in this set in ascending order.

Lexicographical order just means smallest to largest. You have an iterator that provides the items in this order. You don't need recursion for that at all.

I dont think travis is using the TreeSet from the standard library. They are writing their own LinkedList and the code he showed had methods called on the TreeSet which dont exist in the standard library.
But of course only travis can tell us what kind of TreeSet he is using.


standard library TreeSet
so using the iterator would be fine
it's the linked list that is custom.
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
November 03 2016 22:18 GMT
#15811
On November 04 2016 07:05 travis wrote:
ok so if I do a for each to make each linked list node out of the treeset nodes, then how do I actually connect those nodes to form my linked list?

I'm pretty sure you already have something for that. It's probably called "add". Always look at what you have before trying to implement something new.
If you have a good reason to disagree with the above, please tell me. Thank you.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
November 03 2016 22:20 GMT
#15812
On November 04 2016 07:05 travis wrote:
ok so if I do a for each to make each linked list node out of the treeset nodes, then how do I actually connect those nodes to form my linked list?


well i think that's the entire assignment, learning how to create a linked list given some other data and connect the nodes together? just set the next variable to the correct value?
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-03 22:28:32
November 03 2016 22:25 GMT
#15813
On November 04 2016 07:18 spinesheath wrote:
Show nested quote +
On November 04 2016 07:05 travis wrote:
ok so if I do a for each to make each linked list node out of the treeset nodes, then how do I actually connect those nodes to form my linked list?

I'm pretty sure you already have something for that. It's probably called "add". Always look at what you have before trying to implement something new.


nono, i am making the add method for the linked list because I am writing the linked list so I can't do that

I guess I could write an add method and then call it in the for each
but it doesn't seem like that was the directions... eh I guess maybe it was LOL

On November 04 2016 07:20 Blisse wrote:
Show nested quote +
On November 04 2016 07:05 travis wrote:
ok so if I do a for each to make each linked list node out of the treeset nodes, then how do I actually connect those nodes to form my linked list?


well i think that's the entire assignment, learning how to create a linked list given some other data and connect the nodes together? just set the next variable to the correct value?


yes it is the assignment which is why I posted my (attempt at) code to do that. but then I was told to use the iterator which really doesn't solve the essential problem I was addressing, which is adding the TreeSet nodes to my linked list. it just gives me a easier(i guess) way to access the TreeSet nodes

I know how to make a linked list. the issue was taking a bunch of nodes at once and forming them into a linked list, instead of just a method to do it one at a time (which is what I am used to)

maybe I should have just written an add method...
RoomOfMush
Profile Joined March 2015
1296 Posts
November 03 2016 22:29 GMT
#15814
On November 04 2016 07:14 travis wrote:
Show nested quote +
On November 04 2016 07:09 RoomOfMush wrote:
On November 04 2016 07:02 spinesheath wrote:
On November 04 2016 06:50 travis wrote:
Lexicographic

TreeSet doc
iterator()
Returns an iterator over the elements in this set in ascending order.

Lexicographical order just means smallest to largest. You have an iterator that provides the items in this order. You don't need recursion for that at all.

I dont think travis is using the TreeSet from the standard library. They are writing their own LinkedList and the code he showed had methods called on the TreeSet which dont exist in the standard library.
But of course only travis can tell us what kind of TreeSet he is using.


standard library TreeSet
so using the iterator would be fine
it's the linked list that is custom.

Well in that case you iterate over the TreeSet with the iterator as already mentioned. Then you create a new Node of your LinkedList for each element within the TreeSet and append it to the last element of your list. It is always a good idea to link both the first and the last element of your list for easier adds to the end of the list.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-03 22:39:51
November 03 2016 22:39 GMT
#15815
On November 04 2016 07:29 RoomOfMush wrote:
Show nested quote +
On November 04 2016 07:14 travis wrote:
On November 04 2016 07:09 RoomOfMush wrote:
On November 04 2016 07:02 spinesheath wrote:
On November 04 2016 06:50 travis wrote:
Lexicographic

TreeSet doc
iterator()
Returns an iterator over the elements in this set in ascending order.

Lexicographical order just means smallest to largest. You have an iterator that provides the items in this order. You don't need recursion for that at all.

I dont think travis is using the TreeSet from the standard library. They are writing their own LinkedList and the code he showed had methods called on the TreeSet which dont exist in the standard library.
But of course only travis can tell us what kind of TreeSet he is using.


standard library TreeSet
so using the iterator would be fine
it's the linked list that is custom.

Well in that case you iterate over the TreeSet with the iterator as already mentioned. Then you create a new Node of your LinkedList for each element within the TreeSet and append it to the last element of your list. It is always a good idea to link both the first and the last element of your list for easier adds to the end of the list.


ah so like for each one
for(T value : TreeSet<T>) {
tail.next = value;
tail = tail.next;
}

does this work?
it always confuses me conceptually
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
Last Edited: 2016-11-03 22:48:38
November 03 2016 22:46 GMT
#15816
You definitely should use the add method in the constructor. You will definitely need an add, and it does exactly what you need here. No point in inventing the wheel twice. That also would be code duplication, which you should avoid.

Generally, when you implement a container class like LinkedList, always start with the basic operations like add/remove/size and the constructor for an empty container and define everything else in terms of these basic operations. Especially operations that add/remove multiple elements.

Also if you want to know how it would look like if you implemented everything in the constructor, still write the single item add first, call it from within a loop and then replace the call to add with the implementation of add.
If you have a good reason to disagree with the above, please tell me. Thank you.
billy5000
Profile Blog Joined December 2010
United States865 Posts
November 03 2016 23:11 GMT
#15817
One of the things that bothers me is how I should break my code into functions, objects, etc. Basically how I should design my code. Not necessarily design patterns per se, but refactoring and OOP in general. Is there a good book or article that touches this topic? For the most part, I know how to do it, but I just don't know the best way to do it.
Tiger got to hunt, bird got to fly; Man got to sit and wonder, 'Why, why, why?' Tiger got to sleep, bird got to land; Man got to tell himself he understand. Vonnegut
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-04 00:42:24
November 03 2016 23:37 GMT
#15818
continuing on with next problem (sorry to spam the thread, exam is tomorrow )

I am provided

public class LinkedList<T> {
private class Node {
private T data;
private Node next;

private Node(T data) {
this.data = data;
next = null;
}
}
private Node head;
}



question:

write a method public void insertValueAfter(T value, T target)
the value must be inserted directly after the target
you must use recursion, you can use an auxiliary helper method
if you find it useful


my solution


public void insertValueAfter(T value, T target) {
if(head == null) {
return;
}
if(head.data.equals(target) {
result = new Node(value);
result.next = head.next;
head.next = result;
} else {
helperMethod(head, value, target);
}
}

private void helperMethod(Node thisnode, T value, T target) {
if(thisnode.next == null) {
return;
}
if(this.node.next.data.equals(targete) {
result = new Node(value);
result.next = thisnode.next.next;
thisnode.next.next = result;
} else {
helperMethod(thisnode.next, value, target);
}
}




my question: how in the world would I do this *without* a helper method?
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-11-04 00:42:53
November 04 2016 00:31 GMT
#15819
next review question
same problem but

public void insertValueBefore(T value, T target) {

and you *can't* use recursion

my solution:


public void insertValueBefore(T value, T target) {
Node temp = new Node(null);

if(head.data.equals(target)) {
temp.data = value;
temp.next = head;
head = temp;
} else {
temp = head;
while(temp.next != null) {
if(temp.next.data.equals(target)) {
Node result = new Node(value);
result.next = temp.next;
temp.next = result;
result.data = value;
return;
}
temp = temp.next;
}
}
}


edit: tested them in eclipse. besides some small errors it looks like they work. now for some tree problems
tofucake
Profile Blog Joined October 2009
Hyrule19259 Posts
Last Edited: 2016-11-04 01:41:40
November 04 2016 01:41 GMT
#15820
for the recursive one I'd just overload the function for something like


public void insertValueAfter(T value, T target) {
insertValueAfter(value, target, head);
}

public void insertValueAfter(T value, T target, Node start) {
// ...
}


but I'm not sure if that qualifies as a helper, or if you've covered overloading yet

as for non-recursive

public void insertValueBefore(T value, T target) {
Node temp = head;

while (temp != null) {
if (temp.data.equals(target)) {
Node result = new Node(value, temp.next);
temp.next = result;
return;
}

temp = temp.next;
}
}

is clean and simple
Liquipediaasante sana squash banana
Prev 1 789 790 791 792 793 1032 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
08:00
QMC Community Tournament 1
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft: Brood War
Rain 1976
GuemChi 1590
Artosis 671
910 68
Bale 16
ajuk12(nOOB) 14
Dota 2
NeuroSwarm146
Counter-Strike
taco 418
minikerr21
Super Smash Bros
hungrybox450
Other Games
summit1g8367
Doublelift2007
JimRising 514
C9.Mang0352
Day[9].tv333
PiGStarcraft287
Maynarde132
CosmosSc2 24
Organizations
Other Games
gamesdonequick955
BasetradeTV167
Dota 2
PGL Dota 2 - Main Stream20
[ Show 12 non-featured ]
StarCraft 2
• Hupsaiya 119
• CranKy Ducklings SOOP99
• Letter146
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• Day9tv333
Upcoming Events
Afreeca Starleague
8h 17m
Soma vs Soulkey
INu's Battles
9h 17m
SHIN vs Cure
ByuN vs Zoun
PiGosaur Cup
22h 17m
Patches Events
1d 14h
The PondCast
2 days
INu's Battles
2 days
Percival vs TBD
TBD vs herO
OSC
2 days
Replay Cast
2 days
OSC
3 days
BSL: Ladder Tournament
4 days
[ Show More ]
Sparkling Tuna Cup
5 days
Patches Events
5 days
BSL Open Qualifier
5 days
BSL Open Qualifier
5 days
Liquipedia Results

Completed

CSL 2026 AUTUMN (S22)
Blizzard Classic Cup 2026
Copium Cup

Ongoing

ASL Season 22
Super Anchor Qualifying S3
Acropolis #5
Acropolis #5 - GSB
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual

Upcoming

Acropolis #5 - GSC
BSL Season 23
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
HCC Season 3
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.