double linked list

this code is not running although the compiler does not show any warning or error anyone can help?

//doubly linked list

#include <iostream>
using namespace std;

class doublelink
{
public:

struct node
{
node* prev;
int item;
node* next;
};

node* head;

doublelink()
{
head=NULL;
}

node* find(int index) // here the find pointer points to the node whose index number is entered
{ //and NOT TO THE NODE WHICH IS PREVIOUS TO THE NODE WHOSE NUMBER IS ENTERED
node* find_ptr;
find_ptr=head;
find_ptr->prev=NULL;
for (int i=1; i==index; i++)
{
find_ptr=find_ptr->next;
}
return find_ptr;
} // find end

void insert(int index,int item)
{
node *insert=new node;
if (index==1)
{
insert=head;
insert->item=item;
insert->prev=NULL;
insert->next=head;
head=insert;
}
if (index>1)
{
node* middle=find(index-1);
if (middle->next->next!=NULL)
{

insert->next=middle->next;
middle->next->prev=insert;
insert->prev=middle;
middle=insert;
}
if (middle->next->next==NULL)
{
insert->next=middle->next->next;
middle->next->next=insert;
insert->prev=middle->next->prev;
}

}

} // insert end

void del(int index)
{
node* delete_ptr=head;
if (index==1)
{
head->next->prev=NULL;
head=head->next;
}
if (index>1)
{
node* mid=find(index-1);
if(mid->next->next!=NULL)
{

mid->next->prev=mid->prev;
mid->prev->next=mid->next;
}
if(mid->next->next==NULL)
{
mid->next=NULL;
}
}
} //delete end

void display()
{
node* display_ptr;
display_ptr=head;
while (display_ptr->next==NULL)
{
cout<<display_ptr->item;
display_ptr=display_ptr->next;
}
} //display end
}; //class end


void main()
{
doublelink abc;
abc.insert(1,5);
abc.insert(1,6);
abc.insert(1,100);
abc.insert(1,23);
abc.display();
} // main ends
If you think that the code is not running then insert printing debug messages in the code that to see what is the reason.

Why shall others do this instead of you?!
Last edited on
ok i will try it thanks for the suggestion by the way :)
Topic archived. No new replies allowed.