#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
#define LEN sizeof(struct node)
typedef struct node * snode;
struct node
{
char name[10];
snode pleft,pright;
};
snode create(int n) //create double link...
{
snode ptr,head,newnode;
head=(snode)malloc(LEN);
newnode=(snode)malloc(LEN);
head->name[0]='/0';
head->pright=NULL;
head->pleft=NULL;
ptr=head;
if(head==NULL)
{
printf("No enough space!");
exit(0);
}
for(int i=0;i<n;i++)
{
if(newnode==NULL)
{
printf("Sorry!");
exit(0);
}
ptr->pright=newnode;
printf("enter names:");
scanf("%s",head->name);
newnode->pleft=ptr;
newnode->pright=NULL;
ptr=newnode;
}
head->pleft=newnode;
ptr->pright=head;
return head;
}
snode search(snode head,char * selement) //search double link...
{
snode ptr;
char * temp;
ptr=head->pright;
while(head!=ptr)
{
temp=ptr->name;
if(strcmp(temp,selement)==0)
{
return ptr;
}
else
{
ptr=ptr->pright;
}
}
printf("Not found!");
Sleep(3000);
return NULL;
}
void insert(snode head,char * previous,char * insertelement) //insert double link...
{
snode ptr,newnode;
//printf("Before which element you want to insert!");
if((ptr=search(head,previous))==0)
{
printf("No space to insert!");
exit(0);
}
if((newnode=(snode)malloc(LEN))==NULL)
{
printf("No enough space!");
exit(0);
}
strcpy(newnode->name,insertelement);
ptr->pleft->pright=newnode; //a->c;
newnode->pleft=ptr->pleft; //c->a;
newnode->pright=ptr; //c->b;
ptr->pleft=newnode; //b->c;
// return NULL;
}
void del(snode deletelink) //delete double link...
{
deletelink->pleft->pright=deletelink->pright;
deletelink->pright->pleft=deletelink->pleft;
free(deletelink);
}
void print(snode head) //print double link...
{
snode ptr;
ptr=head->pright;
while(ptr!=head)
{
printf("%s",ptr->name);
ptr=ptr->pright;
}
printf("Print success!");
Sleep(3000);
}
void main()
{
//自己按照需要添加
}