• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 21:09
CET 03:09
KST 11:09
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump1Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3
StarCraft 2
General
Weekly Cups (Dec 1-7): Clem doubles, Solar gets over the hump Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win
Tourneys
StarCraft2.fi 15th Anniversary Cup RSL Offline Finals Info - Dec 13 and 14! Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament StarCraft Evolution League (SC Evo Biweekly)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 503 Fowl Play Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night
Brood War
General
Let's talk about Metropolis [ASL20] Ask the mapmakers — Drop your questions BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ Foreign Brood War
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread EVE Corporation Path of Exile ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas Survivor II: The Amazon Sengoku Mafia TL Mafia Community Thread
Community
General
YouTube Thread Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread Things Aren’t Peaceful in Palestine
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
TL+ Announced Where to ask questions and add stream? The Automated Ban List
Blogs
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1537 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
Hyrule19177 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
PiGosaur Monday
01:00
#61
PiGStarcraft506
CranKy Ducklings100
SteadfastSC63
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft609
PiGStarcraft506
elazer 144
SteadfastSC 63
StarCraft: Brood War
Artosis 644
Shuttle 604
NaDa 44
ggaemo 31
Noble 5
Hm[arnc] 4
League of Legends
C9.Mang0378
Nathanias11
Other Games
summit1g8785
Day[9].tv908
JimRising 446
XaKoH 166
Maynarde128
ViBE116
ToD107
Livibee54
CosmosSc2 47
kaitlyn19
fpsfer 1
Organizations
Other Games
gamesdonequick806
BasetradeTV138
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Hupsaiya 85
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota22254
League of Legends
• Doublelift5408
Other Games
• Day9tv908
Upcoming Events
StarCraft2.fi
14h 51m
Tenacious Turtle Tussle
21h 51m
The PondCast
1d 7h
WardiTV 2025
1d 9h
StarCraft2.fi
1d 14h
WardiTV 2025
2 days
StarCraft2.fi
3 days
RSL Revival
3 days
IPSL
3 days
Sziky vs JDConan
RSL Revival
4 days
Classic vs TBD
herO vs Zoun
[ Show More ]
WardiTV 2025
4 days
IPSL
4 days
Tarson vs DragOn
Wardi Open
5 days
Monday Night Weeklies
5 days
Replay Cast
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Acropolis #4 - TS3
RSL Revival: Season 3
Kuram Kup

Ongoing

IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
Slon Tour Season 2
WardiTV 2025
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
RSL Offline Finals
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
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 © 2025 TLnet. All Rights Reserved.