hi
i make code for double linkedlist..
but i didn't have a syntax erroe
.. i don't know where the error .
#include <iostream.h>
struct dnode
{
int info;
dnode *next;
dnode *prev;
};
class dlist {
private :
dnode *head;
dnode *tail;
dnode *current;
public :
void addEnd(int y){
dnode *q;
current=new dnode;
if(head==NULL)
current->prev=current->next=NULL;
else{
for (q=head; q->next!=NULL;q=q->next)
q->next=current;
current->prev=q;
current->next=NULL;
tail=q;
}
}
void forwward_Traversal(){
if(head==NULL)
cout<<"the list has no node.";
else {
dnode *p=head;
while(p){
cout<< p->info ;
p=p->next;
}
}
}
void reverce_Traversal(){
if(head==NULL)
cout<<"the list has no node.";
else {
dnode *p=tail;
while(p){
cout<< p->info ;
p=p->prev;
}
}
}
};
int main () {
dlist obj1;
int num;
int s;
cout << "Enter the size : \n";
cin>>s;
cout << "Enter the NUMBER : \n";
for(int i=0;i<s;i++){
cin>> num;
obj1.addEnd(num);
}
obj1.forwward_Traversal();
obj1.reverce_Traversal();
return 0;
}