• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 18:45
CEST 00:45
KST 07:45
  • 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
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Weekly Cups (Oct 13-19): Clem Goes for Four0BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80Weekly Cups (Sept 29-Oct 5): MaxPax triples up3
StarCraft 2
General
The New Patch Killed Mech! Team Liquid Map Contest #21 - Presented by Monster Energy herO joins T1 Weekly Cups (Oct 13-19): Clem Goes for Four TL.net Map Contest #21: Voting
Tourneys
SC2's Safe House 2 - October 18 & 19 INu's Battles #13 - ByuN vs Zoun Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament $1,200 WardiTV October (Oct 21st-31st)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
BW caster Sayle BSL Season 21 BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ BSL Team A vs Koreans - Sat-Sun 16:00 CET
Tourneys
Azhi's Colosseum - Anonymous Tournament [ASL20] Semifinal B [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN
Strategy
[I] TvP Strategies and Build Roaring Currents ASL final [I] TvZ Strategies and Builds Current Meta
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile Dawn of War IV ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club!
Media & Entertainment
Series you have seen recently... Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1332 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
Turkey779 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
Hyrule19144 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
Next event in 15m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
JuggernautJason77
CosmosSc2 67
StarCraft: Brood War
Britney 11186
Calm 2314
Artosis 543
Mini 355
Soulkey 147
UpATreeSC 90
Aegong 88
NaDa 18
Dota 2
PGG 83
monkeys_forever67
Heroes of the Storm
Liquid`Hasu383
Khaldor147
Other Games
Grubby1627
ScreaM1373
shahzam516
C9.Mang0204
ToD186
Skadoodle171
Maynarde129
Trikslyr48
fpsfer 3
summit1g0
Organizations
Counter-Strike
PGL452
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Hupsaiya 53
• davetesta39
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4144
Other Games
• imaqtpie1746
• Scarra700
• Shiphtur231
Upcoming Events
Replay Cast
15m
Wardi Open
12h 15m
Wardi Open
15h 45m
PiGosaur Monday
1d 1h
Replay Cast
1d 11h
Tenacious Turtle Tussle
2 days
The PondCast
2 days
OSC
2 days
WardiTV Invitational
3 days
Online Event
3 days
[ Show More ]
RSL Revival
4 days
RSL Revival
4 days
WardiTV Invitational
4 days
Afreeca Starleague
5 days
Snow vs Soma
Sparkling Tuna Cup
5 days
WardiTV Invitational
5 days
CrankTV Team League
5 days
RSL Revival
5 days
Wardi Open
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 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.