943,827 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 999
  • C++ RSS
Aug 1st, 2009
0

please very importent ( double linked list )

Expand Post »


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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ju_10_ve is offline Offline
3 posts
since Aug 2009
Aug 1st, 2009
0

Re: please very importent ( double linked list )

What have you tried?
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Aug 1st, 2009
1

Re: please very importent ( double linked list )

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.
Reputation Points: 431
Solved Threads: 17
Posting Whiz in Training
Hiroshe is offline Offline
255 posts
since Jun 2008
Aug 2nd, 2009
0

Re: please very importent ( double linked list )

What have you tried?
i solved other questions !!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ju_10_ve is offline Offline
3 posts
since Aug 2009
Aug 2nd, 2009
0

Re: please very importent ( double linked list )

Click to Expand / Collapse  Quote originally posted by Hiroshe ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ju_10_ve is offline Offline
3 posts
since Aug 2009
Aug 2nd, 2009
0

Re: please very importent ( double linked list )

Click to Expand / Collapse  Quote originally posted by ju_10_ve ...
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
Again, 30 what? Do you mean the value 30 in an integer?
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.
Reputation Points: 431
Solved Threads: 17
Posting Whiz in Training
Hiroshe is offline Offline
255 posts
since Jun 2008
Aug 2nd, 2009
1

Re: please very importent ( double linked list )

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.

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)
  1. while (plist != NULL) {
  2. std::cout << plist->data;
  3. plist = plist->next;
  4. }

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]
2. Assign *prev of new node and *next of last node (Connecting)
NULL <---  [*prev|data|*next] <---> [*prev|data2|*next] <-->  [*prev|new_data|*next]
3. Assign *next of the new node to NULL
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.
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: OpenGL GUI
Next Thread in C++ Forum Timeline: Making a Password Protection





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC