Saturday, November 14, 2009

C++ linked list, another way to simple biuld program?

Is this possible ? So... show me^_^


Who can help me to biuld a simple program using linked list in C++ , like you want to add, delete, insert and modify the stored data in your array.





ex. output in -add-:


the users inputed value are 1,12,23,41,15, and you type "3" in INDEX, 3 is the location of the stored inputs so.. the output is "41", 41 because we started counted in zero 0,1,2,3,4..... in the location 3, 41 is stored and it will display.





--------------------------------------...


INPUT 5 INTEGERS:1,12,23,41,15 %26lt;=1st users inputed value





INDEX: 3 %26lt;= 2nd users inputed value, then press enter





Index 3 is 41 %26lt;= the final output





thanks ^_^v


send to me :setting_hp3danrev@yahoo.com

C++ linked list, another way to simple biuld program?
There are several portions of this program that you can break into separate functions/methods.





1. Handle user information


* you need to be able to write to standard out and read from standard in.





In C++ you can use the cin and cout conventions.





2. You need to have a linked list data structure.





In C++, you can create a class called node and make another class that uses nodes.





e.g.





struct node {


struct node* next;


int datum;


};





then you create a class





class linkedlist {





public:





//need to put a constructor and destructor


...





//methods


void add (int pos, int value);


void delete(int pos);


void modify(int pos, int new_value);





private:


struct node * head;


struct node * tail;


};





3. You need to have some control structure so that you can keep asking the questions until the user wishes to quit.





You have a





while (true) {





//keep asking questions until user enters 'quit'


}





Hope that helps

shoelaces

No comments:

Post a Comment