| | |
Q: in Link List (Daubly Linked List)
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2007
Posts: 3
Reputation:
Solved Threads: 0
- Creat a Daubly Linked List
with 9 node with the following values:
3 ; 2 ; 1 ; 4 ; 6 ; 7 ; 2 ; 8 ; 3;
- print the Daubly Linked List:
- Creat a function number " Special Delete" that searches for a value in the linked list , if the value is found , delete the node after it
-print the Daubly Linked List:
I do that by Linked List but I don't learn the Daubly Linked List:
please do that by Daubly Linked List:
with 9 node with the following values:
3 ; 2 ; 1 ; 4 ; 6 ; 7 ; 2 ; 8 ; 3;
- print the Daubly Linked List:
- Creat a function number " Special Delete" that searches for a value in the linked list , if the value is found , delete the node after it
-print the Daubly Linked List:
I do that by Linked List but I don't learn the Daubly Linked List:
please do that by Daubly Linked List:
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; struct Node { int data; Node *next; Node *prev; Node (int newdata=0) { data = newdata; next = NULL; prev = NULL; } ~Node () { if (data != 0 ) { data = 0; next = NULL; prev = NULL; } } }; class DablyLinkedList { private: Node *first,*last; public: DablyLinkedList(); void buildList(int newdata); void printList(); void SpecialDelete(int OldData); }; DablyLinkedList::DablyLinkedList() { first = NULL; last = NULL; } void DablyLinkedList::buildList(int newdata) { Node *newNode = new Node (newdata); Node *current = first; newNode->prev = NULL; newNode ->next= NULL; if (first == NULL) { first = newNode; last = newNode; } else { while (current->next != NULL) { current = current->next; } current->next = newNode ; current->prev = newNode ; } } void DablyLinkedList::printList() { Node *current= first; cout << "List Contents: " << endl; if (first ==NULL)cout<<" <EMPTY> "<<endl; else while(current != NULL) { cout<<" " << current->data; current = current->next; } } void DablyLinkedList::SpecialDelete(int OldData) { Node *current , *next_ptr; current = first; ; if (first == NULL) cout<< "The List is <EMPTY>"<<endl; else { while(current->next != NULL) { if (current -> data == OldData) { cout<< current ->next-> data<<endl; next_ptr = current ->next ; if (current -> next != NULL) { current-> next = current->next->next ; // current->prev = current->prev->prev ; } else current= NULL; delete next_ptr; } if (current->next != NULL) current = current->next; } } } int main() { DablyLinkedList object; object.buildList(3); object.buildList(2); object.buildList(1); object.buildList(4); object.buildList(6); object.buildList(7); object.buildList(2); object.buildList(8); object.buildList(3); object.printList(); int x; while(x!=0){ cout<< "\n\n=================="<<endl; cout<< "\nPlease enter nuber for delete the number after it : "; cin>> x; object.SpecialDelete(x); cout<< "=================="<<endl; object.printList(); } cin >> x; return 0; }
You haven't asked a question for us to answer.
And for your information it isn't "Daubly Linked List" but "Doubly Linked List"
And for your information it isn't "Daubly Linked List" but "Doubly Linked List"
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- linked list problem!!! (C)
- radix sort using queue and linked list (C++)
- Circular linked list (C)
- printing a linked list (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
Other Threads in the C++ Forum
- Previous Thread: HDC's
- Next Thread: Hash in STL
Views: 947 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






