The Big Programming Thread - Page 791
Forum Index > General Forum |
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
1296 Posts
| ||
findingthelimit
Hong Kong219 Posts
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
Turkey775 Posts
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. | ||
findingthelimit
Hong Kong219 Posts
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
24492 Posts
we have:
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:
and then I would make a helper method that looks like .... eh...
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
Canada3710 Posts
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: 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. | ||
spinesheath
Germany8679 Posts
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. | ||
Deleted User 3420
24492 Posts
| ||
RoomOfMush
1296 Posts
On November 04 2016 07:02 spinesheath wrote: TreeSet doc 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
24492 Posts
On November 04 2016 07:09 RoomOfMush wrote: 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
Germany8679 Posts
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. | ||
Blisse
Canada3710 Posts
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? | ||
Deleted User 3420
24492 Posts
On November 04 2016 07:18 spinesheath wrote: 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 ![]() 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: 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
1296 Posts
On November 04 2016 07:14 travis wrote: 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
24492 Posts
On November 04 2016 07:29 RoomOfMush wrote: 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
Germany8679 Posts
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. | ||
billy5000
United States865 Posts
| ||
Deleted User 3420
24492 Posts
![]() I am provided
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
my question: how in the world would I do this *without* a helper method? | ||
Deleted User 3420
24492 Posts
same problem but public void insertValueBefore(T value, T target) { and you *can't* use recursion my solution:
edit: tested them in eclipse. besides some small errors it looks like they work. now for some tree problems | ||
![]()
tofucake
Hyrule18968 Posts
but I'm not sure if that qualifies as a helper, or if you've covered overloading yet as for non-recursive
is clean and simple | ||
| ||