|
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. |
On February 21 2011 16:04 EscPlan9 wrote: I struggle a lot with fully grasping double linked lists using nodes in C++. I end up trying to draw everything out, a lot of scribbles, taking dozens of minutes designing out how I should be implementing it, and then still struggling when my design doesn't pan out. Any advice for how to get a better grasp on using double linked lists?
I'll be seeing my professor again tomorrow to help me better understand this. Just curious what any of you would recommend for getting better at it.
What exactly don't you understand?
Basically a double-linked list is simply an ordered set of nodes where each node has a pointer to the previous and next node.
The easiest way is to have a DoubleLinkedList object which always has a reference to the first object in the list (and updates it if the first object is removed or something is inserted before it) and you modify the list only through this object. For all insert/delete operations you just need to move through the list node by node and if you found the place to insert/delete, you just need to do something like this (Pseudocode):
InsertAfter: // We add after the current node, so the new nodes prev has to point to the current node new_node->prev = cur_node; // Whatever came after the current node now comes after the new node new_node->next = cur_node->next; // The current node now has the new node following cur_node->next = new_node; // The node following the new node has the new node as prev new_node->next->prev = new_node;
InsertBefore: // Basically the same as InsertAfter, just the other way round new_node->next = cur_node; new_node->prev = cur_node->prev; cur_node->prev = new_node; new_node->prev->next = new_node;
Delete: // The previous node now has the node that follows the current node as the next node cur_node->prev->next = cur_node->next; // The next node gets the prev node of the current node as prev cur_node->next->prev = cur_node->prev;
Ofc you need to check for "first/last node in list" (null pointers), which i'm too lazy to write right now.
You just need to draw a few boxes and add arrows between them.
[...]<-[...]<-[...] [...]...[...]...[...] [...]->[...]->[...]
Then find the place where you want to insert or delete the object and think about where the arrows should point now.
EDIT: You also have to keep in mind the order in which you update the pointers, so you don't accidently lose all pointers to a node.
|
On February 19 2011 15:45 EscPlan9 wrote: I was thinking about C# as one of the next ones I pick up. I read it's sort of like a mix between Java and C++, so should be quick to pickup. Is there a reason I would want to learn C? Does it do something better? It was my understanding that pretty much no company uses C. Rather they want people who know C# and C++ (along with other languages).
C is what most other languages you'll see are based off of. Its lower level and will help you conceptually. As someone else said, it is pivotal to Unix, but there are many other applications. It's good to know a non object-oriented programming language.
|
On February 21 2011 16:22 Morfildur wrote:Show nested quote +On February 21 2011 16:04 EscPlan9 wrote: I struggle a lot with fully grasping double linked lists using nodes in C++. I end up trying to draw everything out, a lot of scribbles, taking dozens of minutes designing out how I should be implementing it, and then still struggling when my design doesn't pan out. Any advice for how to get a better grasp on using double linked lists?
I'll be seeing my professor again tomorrow to help me better understand this. Just curious what any of you would recommend for getting better at it. What exactly don't you understand? Basically a double-linked list is simply an ordered set of nodes where each node has a pointer to the previous and next node. The easiest way is to have a DoubleLinkedList object which always has a reference to the first object in the list (and updates it if the first object is removed or something is inserted before it) and you modify the list only through this object. For all insert/delete operations you just need to move through the list node by node and if you found the place to insert/delete, you just need to do something like this (Pseudocode): InsertAfter: // We add after the current node, so the new nodes prev has to point to the current node new_node->prev = cur_node; // Whatever came after the current node now comes after the new node new_node->next = cur_node->next; // The current node now has the new node following cur_node->next = new_node; // The node following the new node has the new node as prev new_node->next->prev = new_node; InsertBefore: // Basically the same as InsertAfter, just the other way round new_node->next = cur_node; new_node->prev = cur_node->prev; cur_node->prev = new_node; new_node->prev->next = new_node; Delete: // The previous node now has the node that follows the current node as the next node cur_node->prev->next = cur_node->next; // The next node gets the prev node of the current node as prev cur_node->next->prev = cur_node->prev; Ofc you need to check for "first/last node in list" (null pointers), which i'm too lazy to write right now. You just need to draw a few boxes and add arrows between them. [...]<-[...]<-[...] [...]...[...]...[...] [...]->[...]->[...] Then find the place where you want to insert or delete the object and think about where the arrows should point now. EDIT: You also have to keep in mind the order in which you update the pointers, so you don't accidently lose all pointers to a node.
Basically do what he said. Draw boxes and understand conceptually how you need to update pointers to perform the required operations. Then code it. When you run into a bug, try to figure how what went wrong in your design, and patch it. You'll most likely have forgotten a corner case.
|
Hey TL Programmers,
I've been brainstorming and trying to solve a problem for a while now it's a web programming project but I need a solution in pseudo code.
I have a large db of areas, about 17,000 results and I need to display these on a webpage for users to select their regions. I can divide it up into state locations but it still results in about 3000-4000 results per page. This ends up being a massive 1mb+ page if implemented as a straight forward list.
How would all the awesome TL programmers solve this? My current implementation involves Selecting a state -> loading results via jquery -> selecting checkboxes & submission. This works fine however if a user wanted to select regions from multiple states it'd just not be possible without saving everything to sessions before posting the results.
Can anyone think if a more elegant solution?
|
Consider paging? Why would you need to show 4000 results on one page?
|
On February 21 2011 17:04 ibutoss wrote: Hey TL Programmers,
I've been brainstorming and trying to solve a problem for a while now it's a web programming project but I need a solution in pseudo code.
I have a large db of areas, about 17,000 results and I need to display these on a webpage for users to select their regions. I can divide it up into state locations but it still results in about 3000-4000 results per page. This ends up being a massive 1mb+ page if implemented as a straight forward list.
How would all the awesome TL programmers solve this? My current implementation involves Selecting a state -> loading results via jquery -> selecting checkboxes & submission. This works fine however if a user wanted to select regions from multiple states it'd just not be possible without saving everything to sessions before posting the results.
Can anyone think if a more elegant solution?
I think the best solution would be something like 3 checkboxes and a javascript way to add the result as an input value to the submit form. I don't know the exact filter criteria, so i'll just assume state, area, city and you have to adapt it to your problem:
[Select: State] [Select: Area] [Select: City] [[Button: Add]]
The user can select a state, then the area gets filled via Ajax. Then he selects the area, which results in the cities being loaded through Ajax. The area and city selects should be disabled and empty until he selected a state (and then an area to enable cities). This way you can even allow something like "any city" or "any area". If the result sets are still too large, you might even add a "A...", "B...", ... select to filter it by starting letter.
It's hard to suggest something though, since the problem description is quite vague.
|
On February 21 2011 18:30 Morfildur wrote:Show nested quote +On February 21 2011 17:04 ibutoss wrote: Hey TL Programmers,
I've been brainstorming and trying to solve a problem for a while now it's a web programming project but I need a solution in pseudo code.
I have a large db of areas, about 17,000 results and I need to display these on a webpage for users to select their regions. I can divide it up into state locations but it still results in about 3000-4000 results per page. This ends up being a massive 1mb+ page if implemented as a straight forward list.
How would all the awesome TL programmers solve this? My current implementation involves Selecting a state -> loading results via jquery -> selecting checkboxes & submission. This works fine however if a user wanted to select regions from multiple states it'd just not be possible without saving everything to sessions before posting the results.
Can anyone think if a more elegant solution? I think the best solution would be something like 3 checkboxes and a javascript way to add the result as an input value to the submit form. I don't know the exact filter criteria, so i'll just assume state, area, city and you have to adapt it to your problem: [Select: State] [Select: Area] [Select: City] [[Button: Add]] The user can select a state, then the area gets filled via Ajax. Then he selects the area, which results in the cities being loaded through Ajax. The area and city selects should be disabled and empty until he selected a state (and then an area to enable cities). This way you can even allow something like "any city" or "any area". If the result sets are still too large, you might even add a "A...", "B...", ... select to filter it by starting letter. It's hard to suggest something though, since the problem description is quite vague.
This will work but this design will mean that the user is limited to one input at a time, you can probably implement some sort of cart so user can save them and submit in one go later.
We still don't know what exactly the results are and if we can assume that there exists more properties then naturally we can expect more filtering.
You can of course implement a paging system much like TL threads. I think whatever you do, you will need to stop showing 4000 results in one go, the end user don't need to see that much information.
|
On February 21 2011 19:17 haduken wrote:Show nested quote +On February 21 2011 18:30 Morfildur wrote:On February 21 2011 17:04 ibutoss wrote: Hey TL Programmers,
I've been brainstorming and trying to solve a problem for a while now it's a web programming project but I need a solution in pseudo code.
I have a large db of areas, about 17,000 results and I need to display these on a webpage for users to select their regions. I can divide it up into state locations but it still results in about 3000-4000 results per page. This ends up being a massive 1mb+ page if implemented as a straight forward list.
How would all the awesome TL programmers solve this? My current implementation involves Selecting a state -> loading results via jquery -> selecting checkboxes & submission. This works fine however if a user wanted to select regions from multiple states it'd just not be possible without saving everything to sessions before posting the results.
Can anyone think if a more elegant solution? I think the best solution would be something like 3 checkboxes and a javascript way to add the result as an input value to the submit form. I don't know the exact filter criteria, so i'll just assume state, area, city and you have to adapt it to your problem: [Select: State] [Select: Area] [Select: City] [[Button: Add]] The user can select a state, then the area gets filled via Ajax. Then he selects the area, which results in the cities being loaded through Ajax. The area and city selects should be disabled and empty until he selected a state (and then an area to enable cities). This way you can even allow something like "any city" or "any area". If the result sets are still too large, you might even add a "A...", "B...", ... select to filter it by starting letter. It's hard to suggest something though, since the problem description is quite vague. This will work but this design will mean that the user is limited to one input at a time, you can probably implement some sort of cart so user can save them and submit in one go later. We still don't know what exactly the results are and if we can assume that there exists more properties then naturally we can expect more filtering. You can of course implement a paging system much like TL threads. I think whatever you do, you will need to stop showing 4000 results in one go, the end user don't need to see that much information.
Yeah I can always use pagination but it's not the best way to go about it. I actually believe I need additional information stored in my database which unfortunately I'll have to purchase/source from a mapping company. I'm trying to breakdown regions of countries so a user could select say several suburbs or a entire city rather than a entire list of every suburb possible which is what I'm currently dealing with.
|
Wow, I feel stupid. Nonetheless, thanks for the advice on linking the nodes together.
I realized after much frustration my problem wasn't from linking the nodes together correctly, it was from me making a typographical area in one of my mutator functions that threw everything off. Now it works as it should. (I had a mutator called setNext that is called to link a previous node to a current node).
|
On February 21 2011 19:52 ibutoss wrote:Show nested quote +On February 21 2011 19:17 haduken wrote:On February 21 2011 18:30 Morfildur wrote:On February 21 2011 17:04 ibutoss wrote: Hey TL Programmers,
I've been brainstorming and trying to solve a problem for a while now it's a web programming project but I need a solution in pseudo code.
I have a large db of areas, about 17,000 results and I need to display these on a webpage for users to select their regions. I can divide it up into state locations but it still results in about 3000-4000 results per page. This ends up being a massive 1mb+ page if implemented as a straight forward list.
How would all the awesome TL programmers solve this? My current implementation involves Selecting a state -> loading results via jquery -> selecting checkboxes & submission. This works fine however if a user wanted to select regions from multiple states it'd just not be possible without saving everything to sessions before posting the results.
Can anyone think if a more elegant solution? I think the best solution would be something like 3 checkboxes and a javascript way to add the result as an input value to the submit form. I don't know the exact filter criteria, so i'll just assume state, area, city and you have to adapt it to your problem: [Select: State] [Select: Area] [Select: City] [[Button: Add]] The user can select a state, then the area gets filled via Ajax. Then he selects the area, which results in the cities being loaded through Ajax. The area and city selects should be disabled and empty until he selected a state (and then an area to enable cities). This way you can even allow something like "any city" or "any area". If the result sets are still too large, you might even add a "A...", "B...", ... select to filter it by starting letter. It's hard to suggest something though, since the problem description is quite vague. This will work but this design will mean that the user is limited to one input at a time, you can probably implement some sort of cart so user can save them and submit in one go later. We still don't know what exactly the results are and if we can assume that there exists more properties then naturally we can expect more filtering. You can of course implement a paging system much like TL threads. I think whatever you do, you will need to stop showing 4000 results in one go, the end user don't need to see that much information. Yeah I can always use pagination but it's not the best way to go about it. I actually believe I need additional information stored in my database which unfortunately I'll have to purchase/source from a mapping company. I'm trying to breakdown regions of countries so a user could select say several suburbs or a entire city rather than a entire list of every suburb possible which is what I'm currently dealing with.
Why not just have a tagging system? A Tag can be a region or a city or what ever defined grouping that the user chose to have. the tag will have a many2many relationship with the suburbs. This way instead of returning suburbs, you return tags.
|
On February 22 2011 16:50 haduken wrote:
Why not just have a tagging system? A Tag can be a region or a city or what ever defined grouping that the user chose to have. the tag will have a many2many relationship with the suburbs. This way instead of returning suburbs, you return tags.
Thanks for the suggestion I've actually used it as part of my solution. Users can now enter a city/suburb/postcode/tag and it'll auto-complete via ajax.
|
Can anyone recommend a forum for casual nerdspeak. I have a lot of questions like hooking lots of things to one outlet, etc. not necessarily just programming.
Also, anyone have experience with XNA, Silverlight, Windows 7 Phone programming? Any particularly useful tutorials you may recommend?
|
On February 27 2011 01:08 alexpnd wrote: Can anyone recommend a forum for casual nerdspeak. I have a lot of questions like hooking lots of things to one outlet, etc. not necessarily just programming.
Also, anyone have experience with XNA, Silverlight, Windows 7 Phone programming? Any particularly useful tutorials you may recommend?
Reddit, stackoverflow, hacker news. (for the forums part)
|
Anyone have recomendations on news or discussion sites on programming? For example about the latest VC++ runtime or something. The ones I googled blowed :p
|
I'm not sure if you noticed but there is a post right above yours.
|
stackoverflow is heavily recommended: http://stackoverflow.com/ if you want strictly programming.
But the main site stackexchange.com is great if you want to see discussions on lots of stuff including general computing, hardware topics, game development and stuff outside the realm of computers.
|
I hate to post this semi irrelevant post in this thread but my mind is perpetually upset by this.
Has anyone else used "programing" in the place of "programming?" Has anyone been confused by this? It technically is the same word according to dictionaries, but my friend started using it, and my mind keeps reading it like pro-gaming only in engrish with an "r" for "pro-grayming" even when I read programming now. Sorry for the tangent!
|
On March 02 2011 18:04 Ace wrote:stackoverflow is heavily recommended: http://stackoverflow.com/ if you want strictly programming. But the main site stackexchange.com is great if you want to see discussions on lots of stuff including general computing, hardware topics, game development and stuff outside the realm of computers.
Yeah I forgot to add that, I visit stackoverflow daily :D
Havn't seen stackexchange though, gonna have a look at it but it appears to just be a hub for other Q&A sites like stackoverflow, and nothing about discussions or news-related stuff
|
On February 18 2011 10:17 heishe wrote:Show nested quote +On February 18 2011 01:21 Pigsquirrel wrote:I have a C++ question. How would I go about doing something like this: #include <iostream> #include <fstream> #include <string.h> using namespace std;
int main () { string fileName = "example.txt" ofstream myfile; myfile.open (fileName); myfile << "Writing this to a file.\n"; myfile.close(); return 0; }
It appears the string is the wrong variable type. What type should I use and is it possible anyway? EDIT Google Came Through:
#include <iostream> #include <fstream> #include <string.h> using namespace std;
int main () { string l="example.txt"; const char *p; p=l.c_str(); ofstream myfile; myfile.open (p); myfile << "Writing this to a file.\n"; myfile.close(); return 0; }
Why do you use <iostream> <fstream> and then <string.h> instead of <string> ? Habit I guess, wasn't aware that plain <string> would work in place of <string.h>
|
Okay, I am supposed to be making a linked list with java and I have a different problem than the person who brought up linked lists earlier. I understand the linked list concept very well. And I would love to be able to do it in C because I feel like pointers would make it easier. But I have to do it in Java.
This is the crux of my problem: I simply do not know how to iteratively create objects (see how this ties in with linked lists further down). According to my faulty understanding of objects, I need a variable for every object I make. Thus every time I make an object, I need to write a line like this.
CLASS object-variable = new CLASS();
If someone could be so kind to explain why this is unnecessary in java, and what is wrong with my understanding of objects that hinders me from seeing the light, that would be great. This is really all I'm asking, but if you want specifics keep reading.
In the way I have it set up, the linked list is (when instantiated) an object of objects. The objects that make the list are simple nodes with two data values (some integer and a reference value to the second node). The linked list class takes an array input and generates a linked list based on the size of the array. So with a length 100 array, the linked list class would need to instantiate 100 nodes. And I would need to do this iteratively of course (or recursively if you want). I just need a way to make these nodes without each of them needing its own variable.
|
|
|
|