• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 22:30
CEST 04:30
KST 11:30
  • 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] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7
Community News
Weekly Cups (August 10-16): SHIN doubles2GSTL Returns in 2026!45Weekly Cups (Aug 3-9): Protoss get shut out7RSL goes to London! 2026 Offline Finals Nov 21-2212Weekly Cups (July 27-Aug 2): SHIN's big week0
StarCraft 2
General
GSTL Returns in 2026! SC4ALL II: SC2 Player Announcement 6/8 - Maru Balance hotfix patch 5.0.16b (July 16) Serral wins Maestros of the Game 2 Weekly Cups (August 10-16): SHIN doubles
Tourneys
SC2 AI Tournament 2026 Fall 2026 GSTL Announcement Master Swan Open (Global Bronze-Master 2) PIG STY FESTIVAL 8.0! (13 - 23 August) WardiTV Mondays
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
The PondCast: SC2 News & Results Mutation # 539 Thunder Dome Mutation # 538 Media Blackout Mutation # 537 Hostile Territory
Brood War
General
BW General Discussion Are you ready for ASL 22? NEW HYPE VIDEO [ASL22] Ro24 Preview: Summer's End BGH Auto Balance -> http://bghmmr.eu/ How Famous was FlaSh before his Debut?
Tourneys
[ASL22] Ro24 Group C Small VOD Thread 2.0 [Megathread] Daily Proleagues KCM Race Survival 2026 Season 3
Strategy
Odyssey Mineral Stack Saturation Fighting Spirit mining rates Any training maps people recommend? Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Anyone here play Quakeworld back in the day? Stormgate/Frost Giant Megathread EVE Corporation
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Artificial Intelligence Thread Russo-Ukrainian War Thread Dating: How's your luck? The Letting Off Steam Thread
Fan Clubs
The Creator Fan Club MarineLorD Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread Series you have seen recently...
Sports
Football (Soccer) Thread MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Simple Questions Simple Answers FPS when play League Of Legend on laptop
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Young Players Exit Esports E…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5976 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
Hyrule19237 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
00:00
Patches' Patch Clash #9
CranKy Ducklings144
CranKy Ducklings SOOP12
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RuFF_SC2 171
CosmosSc2 14
StarCraft: Brood War
NaDa 21
Dota 2
The International59781
monkeys_forever380
NeuroSwarm82
Counter-Strike
summit1g9314
taco 345
minikerr224
Super Smash Bros
hungrybox524
Mew2King41
Other Games
Liquid`RaSZi1854
C9.Mang0187
Maynarde112
ViBE89
Trikslyr58
[ Show 12 non-featured ]
StarCraft 2
• Berry_CruncH152
• Response 4
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• RayReign 27
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo352
Upcoming Events
Escore
7h 30m
PiG Sty Festival
9h 30m
Serral vs Reynor
HeRoMaRinE vs herO
Big Brain Bouts
13h 30m
MaNa vs Kelazhur
Nicoract vs HeRoMaRinE
Serral vs Cure
CranKy Ducklings
1d 7h
PiG Sty Festival
1d 9h
Zoun vs Solar
SHIN vs Maru
Patches Events
1d 13h
Sparkling Tuna Cup
2 days
PiG Sty Festival
2 days
The Patches Monday
3 days
GSL
4 days
[ Show More ]
PiGosaur Cup
4 days
Replay Cast
4 days
Replay Cast
5 days
The PondCast
6 days
Liquipedia Results

Completed

Proleague 2026-08-19
CranK Gathers Season 4: BW vs SC2 Team League
Eternal Conflict S2 Finale

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL Season 22: Qualifier 1
Escore Tournament S3: W8
RSL Revival: Season 6
PiG Sty Festival 8.0
META DYMY #4
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026

Upcoming

CSL Season 22: Qualifier 2
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - TRS
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Big Dog Cup 2026 Div 1
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
Thunderpick World Champ. '26
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
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.