i am working on a movie database and i have output from my file that i want to load into my linked list,no problem opening file but when i run this function it enters junk values in the list and only works if i enter all the strings without spaces or seperated by special characters.
i am reading this from the txt file
SHAWSHANK REDEMPTION 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX PART1 120 5 MYSTERY 2009 ENGLISH 3
THE MATRIX PART2 120 5 MYSTERY 2009 ENGLISH 3
this is the code for load text from file into a linkedlist(doubly)
int mrelease_year,mamount, mrating,mruntime;
while (fromfile >> mname >> mgenre >> mlanguage >> mrelease_year>>mamount>>mrating>>mruntime)
/* do something with name, var1 etc. */
cout << mname<<mgenre<<mlanguage<<mrelease_year<<mamount<<mrating<<mruntime<<endl;
the code for doublylinkedlist
void double_llist::create_list(string mname,
int mrating,int mruntime)
struct node *s, *temp;
temp = new(struct node);
temp->name = mname;
temp->next = NULL;
if (start == NULL)
temp->prev = NULL;
start = temp;
s = start;
while (s->next != NULL)
s = s->next;
s->next = temp;
temp->prev = s;
my class and node struct for linkedlist
* Node Declaration
struct node *next;
struct node *prev;
void create_list(string mname,
int mrating,int mruntime);
void search_element(node *head, intvalue);
void update(node *q ,intvalue);
start = NULL;
A couple of minutes with the debugger would have shown you that you cannot enter text like that and expect the system to realise that the film title comprises more than one word. Stream input breaks fields up at white space so in your first case you will have something like:
mname = SHAWSHANK
mgenre = REDEMPTION
mlanguage = 120
mrelease_year = 5
mamount = MYSTERY - which is not an integer
mrating = 2009
mruntime = ENGLISH - also not an integer
the final 3 will now go into the title next time round the loop.
You need to split the lines manually so that you can separate the title from the other fields. You could just read the entire line, tokenise it into an array, and then work backwards field by field. Whatever is left at the beginning of the array can be recombined into a single string which is the title.
I have Dev C++ on my system to practice writing C++ code from my C++ Programming for the Absolute Beginner book. So far, the constant repetition and copying have improved my muscle memory. Then, recently, I just noticed that this application could autocomplete my line.
My biggest worry is that this autocomplete thing would make me fail the Computer Science placement exam. I really want to take the placement exam, so then I can get tested into the software development class and skip the introductory CS classes. On the school's website, it says that the placement exam takes place on paper and pencil, so that implies I should know how to write everything down to smallest detail and get it accurate enough so the algorithms would run correctly.
Should beginners use Autocomplete? Maybe it's good practice for a beginner to write code on paper and then transfer the code onto the computer?
I guess you never had the joy of writing your code in pencil, on fixed width coding sheets. These were then sent to the data prep department to be punched onto Hollerith (80 column) cards, before being submitted to the computer room for compilation. And then you had to wait a couple of hours for the results which showed you had missed a comma on the second line.
I have however worked on FPGAs, that's a similarly slow process of building/routing. You're not writing things on paper but you're definitely waiting for a really long time for synthesis and routing. I was working on these guys a few years ago now but our builds would take about a couple of hours too. You'd be really disappointed when things didn't quite work or you forgot some debug traces.
It depends how much work your auto-complete does for you. As a learner, you should avoid auto-complete that makes classes and sets of methods for you. If however, all it's doing is completing a word, well... you're learning to program, not to spell... so that little bit of help won't undo what you're learning.
At the end of the day what will make you a better programmer will ultimately be how many hours you spend programming. Practice, practice, practice....
Definitely use a whiteboard or paper for architecting a complicated system (or a software tool like Visio). Last thing you want to do is spend a bunch of time writing software that doesn't really make sense in the grand scale of things (architecture-wise).
Printing aside, you need to first verify that the tree is being built correctly. The only way to do that is to single step through each line of code (the stree() function) using the debugger. Note the values of info, left, and right along the way. As you build the tree on paper, what you see in the debugger should match.
Are you trying to print the tree contents pre-order, in-order, or post-order?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles