Q: in Link List (Daubly Linked List)

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2007
Posts: 3
Reputation: *~ Salam ~* is an unknown quantity at this point 
Solved Threads: 0
*~ Salam ~* *~ Salam ~* is offline Offline
Newbie Poster

Q: in Link List (Daubly Linked List)

 
0
  #1
Jul 24th, 2007
- 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:


  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct Node
  6. {
  7. int data;
  8. Node *next;
  9. Node *prev;
  10.  
  11. Node (int newdata=0)
  12. {
  13. data = newdata;
  14. next = NULL;
  15. prev = NULL;
  16. }
  17.  
  18. ~Node ()
  19. {
  20. if (data != 0 )
  21. { data = 0;
  22. next = NULL;
  23. prev = NULL;
  24. }
  25. }
  26. };
  27.  
  28. class DablyLinkedList
  29. {
  30. private:
  31. Node *first,*last;
  32. public:
  33. DablyLinkedList();
  34.  
  35. void buildList(int newdata);
  36. void printList();
  37. void SpecialDelete(int OldData);
  38. };
  39. DablyLinkedList::DablyLinkedList()
  40. {
  41. first = NULL;
  42. last = NULL;
  43. }
  44.  
  45.  
  46. void DablyLinkedList::buildList(int newdata)
  47. {
  48. Node *newNode = new Node (newdata);
  49.  
  50. Node *current = first;
  51. newNode->prev = NULL;
  52. newNode ->next= NULL;
  53.  
  54.  
  55. if (first == NULL)
  56. {
  57. first = newNode;
  58. last = newNode;
  59. }
  60. else
  61. { while (current->next != NULL)
  62. {
  63. current = current->next;
  64.  
  65. }
  66.  
  67. current->next = newNode ;
  68. current->prev = newNode ;
  69.  
  70.  
  71. }
  72.  
  73. }
  74.  
  75. void DablyLinkedList::printList()
  76. {
  77. Node *current= first;
  78. cout << "List Contents: " << endl;
  79. if (first ==NULL)cout<<" <EMPTY> "<<endl;
  80. else
  81. while(current != NULL)
  82. {
  83. cout<<" " << current->data;
  84. current = current->next;
  85. }
  86. }
  87.  
  88. void DablyLinkedList::SpecialDelete(int OldData)
  89. {
  90. Node *current , *next_ptr;
  91. current = first;
  92. ;
  93. if (first == NULL)
  94. cout<< "The List is <EMPTY>"<<endl;
  95.  
  96. else
  97. {
  98. while(current->next != NULL)
  99. {
  100.  
  101.  
  102. if (current -> data == OldData)
  103. {
  104. cout<< current ->next-> data<<endl;
  105.  
  106. next_ptr = current ->next ;
  107. if (current -> next != NULL)
  108. {
  109. current-> next = current->next->next ;
  110. // current->prev = current->prev->prev ;
  111. }
  112.  
  113. else
  114. current= NULL;
  115. delete next_ptr;
  116. }
  117.  
  118. if (current->next != NULL)
  119. current = current->next;
  120. }
  121. }
  122.  
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129. int main()
  130. {
  131. DablyLinkedList object;
  132.  
  133. object.buildList(3);
  134. object.buildList(2);
  135. object.buildList(1);
  136. object.buildList(4);
  137. object.buildList(6);
  138. object.buildList(7);
  139. object.buildList(2);
  140. object.buildList(8);
  141. object.buildList(3);
  142.  
  143. object.printList();
  144. int x;
  145. while(x!=0){
  146. cout<< "\n\n=================="<<endl;
  147. cout<< "\nPlease enter nuber for delete the number after it : ";
  148. cin>> x;
  149. object.SpecialDelete(x);
  150. cout<< "=================="<<endl;
  151. object.printList();
  152. }
  153. cin >> x;
  154.  
  155. return 0;
  156. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 3
Reputation: *~ Salam ~* is an unknown quantity at this point 
Solved Threads: 0
*~ Salam ~* *~ Salam ~* is offline Offline
Newbie Poster

Re: Q: in Link List (Daubly Linked List)

 
0
  #2
Jul 24th, 2007
Hi;

Not any one ansewr

?????????????????????????????????
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Q: in Link List (Daubly Linked List)

 
0
  #3
Jul 24th, 2007
You haven't asked a question for us to answer.
And for your information it isn't "Daubly Linked List" but "Doubly Linked List"
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 947 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC