| | |
please very importent ( double linked list )
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2009
Posts: 3
Reputation:
Solved Threads: 0
plz i wont soulotion of my questions by codes :
where list is the node pointer for the whole double linked list
how i can :
1- add a node after the node that has 30
2- delete a node at the beginning of the list
3- delete a node before 30
4- count how many nodes are in the list
5- count how many nodes are greater than 10
6- count how many even %odd nodes in the list !!
7- print all the nodes in the list but ( backwards )
8- split the double list into 2 , where the first list has a pointer list and the other one has the pointer head , and it starts with the node 15 !!
make answer what you know plz
Last edited by ju_10_ve; Aug 1st, 2009 at 8:03 pm.
1. We will not just give you the code. We might however, help you find problems in code you have already written or tell you how to approch a particular problem.
2. What do you mean by a double linked list? Do you mean a nested linked list (a list inside a list).
3. Make that list of question's more clear! Look at question 1:
>1- add a node after the node that has 30
30 what?
4. Don't bold your entire message.
2. What do you mean by a double linked list? Do you mean a nested linked list (a list inside a list).
3. Make that list of question's more clear! Look at question 1:
>1- add a node after the node that has 30
30 what?
4. Don't bold your entire message.
"Sometimes, when I lie in bed at night and look up at the stars, I think to myself, "Man! I really need to fix that roof."-Jack Handy
•
•
Join Date: Aug 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
1. We will not just give you the code. We might however, help you find problems in code you have already written or tell you how to approch a particular problem.
2. What do you mean by a double linked list? Do you mean a nested linked list (a list inside a list).
3. Make that list of question's more clear! Look at question 1:
>1- add a node after the node that has 30
30 what?
4. Don't bold your entire message.
double linked list .. in the web :
http://upload.wikimedia.org/wikipedi...inked_list.png
and the question 1 its mean the 30 inside the node
•
•
•
•
double linked list .. in the web :
http://upload.wikimedia.org/wikipedi...inked_list.png
and the question 1 its mean the 30 inside the node
Why not get your hands a little dirty, eh? Post your code of a doubly linked list. Also post the for a node counter function, even if it dosen't work. If it dosen't work, post your compiler output and tell us why you think it dosen't work.
If you can do that, we will gladly help you. Good luck.
"Sometimes, when I lie in bed at night and look up at the stars, I think to myself, "Man! I really need to fix that roof."-Jack Handy
If you truly understand the concept of doubly-linked list, these problems would be very easy. Lets start with basic doubly-linked list concept. Doubly-linked list data structure consist of 3 important components: set of data, pointer to address of previous data (*prev), and pointer to address of next data (*next). When you learn linked-list, you will often heard the term "node". Node is simply just a record.
Let say that we have kth nodes and we want to display all of data out into the screen. Assuming plist is the address of our first node.
To count total nodes, to count nodes that have even or odd data value, or to print backward also use this technique except with some extra conditions.
To add new node in, no matter at what position it will be inserted in (at beginning, at middle, or at the end), you need to allocate memory location to store new node and assign proper *next and *prev address. For example, you want to insert new node at the end of your list. To do so, you need to know the address of your last node. Then, assign the *prev of the new node to the address of the last node and then *next of the new node point to NULL which to determine that it is the end of the list. Then *next of the last node must assign to the address of the new node.
1. Allocating memory for new node (the red text represent new node)
2. Assign *prev of new node and *next of last node (Connecting)
3. Assign *next of the new node to NULL
Last but not least, removing the node from the list is also important. First you need to know the address of the node you want to delete. Then connect the previous node of node you want to delete to its next node. Then de-allocate its memory
1. (Red-text represent node you want to delete)
2. Connect its previous node to its next node
3. De-allocating its memory
So the most important thing about linked-list is about assigning the right address of next and previous node. More information, go to http://en.wikipedia.org/wiki/Doubly-linked_list.
These should give half of the answer of your questions and it's matter of how to figure another half of the answer.
NULL <--- [*prev|data|*next] <---> [*prev|data2|*next] <--> [*prev|data3|*next] --> NULL
Let say that we have kth nodes and we want to display all of data out into the screen. Assuming plist is the address of our first node.
C++ Syntax (Toggle Plain Text)
while (plist != NULL) { std::cout << plist->data; plist = plist->next; }
To count total nodes, to count nodes that have even or odd data value, or to print backward also use this technique except with some extra conditions.
To add new node in, no matter at what position it will be inserted in (at beginning, at middle, or at the end), you need to allocate memory location to store new node and assign proper *next and *prev address. For example, you want to insert new node at the end of your list. To do so, you need to know the address of your last node. Then, assign the *prev of the new node to the address of the last node and then *next of the new node point to NULL which to determine that it is the end of the list. Then *next of the last node must assign to the address of the new node.
1. Allocating memory for new node (the red text represent new node)
NULL <--- [*prev|data|*next] <---> [*prev|data2|*next] --> NULL [*prev|new_data|*next]
NULL <--- [*prev|data|*next] <---> [*prev|data2|*next] <--> [*prev|new_data|*next]
NULL <--- [*prev|data|*next] <---> [*prev|data2|*next] <--> [*prev|new_data|*next] --> NULL
Last but not least, removing the node from the list is also important. First you need to know the address of the node you want to delete. Then connect the previous node of node you want to delete to its next node. Then de-allocate its memory
1. (Red-text represent node you want to delete)
NULL <--- [*prev|data|*next] <---> [*prev|data2|*next] <--> [*prev|data3|*next] --> NULL
2. Connect its previous node to its next node
NULL <--- [*prev|data|*next] <-------------------------> [*prev|data3|*next] --> NULL [*prev|data2|*next]
3. De-allocating its memory
NULL <--- [*prev|data|*next] <---> [*prev|data3|*next] --> NULL
So the most important thing about linked-list is about assigning the right address of next and previous node. More information, go to http://en.wikipedia.org/wiki/Doubly-linked_list.
These should give half of the answer of your questions and it's matter of how to figure another half of the answer.
Last edited by invisal; Aug 2nd, 2009 at 3:13 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
![]() |
Similar Threads
- traversing backwards thru double linked list (C++)
- trouble with double linked list (C++)
- double linked list array of pointers, on the right track? (C++)
- Double linked list - possible memory error (C)
- Issues with double linked list (C++)
- Double-linked list in contiguous memory. (C)
Other Threads in the C++ Forum
- Previous Thread: OpenGL GUI
- Next Thread: Making a Password Protection
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






