- 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:

#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;
}

Recommended Answers

All 2 Replies

Hi;

Not any one ansewr

?????????????????????????????????
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You haven't asked a question for us to answer.
And for your information it isn't "Daubly Linked List" but "Doubly Linked List"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.