#include <stdio.h>
#include <malloc.h>
typedef struct Node
{
struct Node *prior;
struct Node *next;
int num;
}Node;
Node *createNode(int value)
{
Node *p=(Node *)malloc(sizeof(Node));
p->num=value;
p->next=p->prior=NULL;
return p;
}
Node *create_empty_list()
{
return createNode(0);
}
Node *insert(Node *head,int num)
{
Node *p2,*p;
p2=head;
p=createNode(num);
if(head->next==NULL)// 如果为空链表的话
{
head->next=p;
p->next=NULL;
p->prior=NULL;
head->prior=p;
}
else
{
/*while(p2->next!=NULL) //如果不是空链表,遍历得到最后一个节点
{
p2=p2->next;
}
p2->next=p;
p->next=NULL;
p->prior=p2;
head->prior=p;*/
head->next->prior=p;
p->prior=NULL;
p->next=head->next;
head->next=p;
}
}
void output(Node *h)
{
Node *l;
l=h->next;
while(l!=NULL)
{
printf("%d\n",l->num);
l=l->next;
}
}
int list_len(Node *head)
{
int length=0;
Node *p;
p=head->next;
while(p!=NULL)
{
length++;
p=p->next;
}
head->num=length;
return length;
}
Node *index_list(Node *head,int number)
{
Node *p;
p=head->next;
while(p != NULL && p->num != number)
{
p = p->next;
}
if(p->num == number)
{
return p;
}
else
return NULL;
}
Node *delete_node(Node *head,int number)
{
Node *p;
p=index_list(head,number);
if(p->prior == NULL)
{
head->next=p->next;
}
else
p->prior->next=p->next;
}
int main(int argc, char *argv[])
{
Node *head,*p1;
head = create_empty_list(); //创建空链表
insert(head,11); //插入数据
insert(head,19);
insert(head,7);
insert(head,6);
insert(head,34);
insert(head,56);
insert(head,67);
insert(head,78);
insert(head,13);
insert(head,15);
insert(head,8);
printf("有%d个数据\n",list_len(head));
p1 = index_list(head,78);
if(p1== NULL) return 0;
printf("找到的数据是%d\n",p1->num);
delete_node(head,8);
output(head);
return 0;
}
#include <malloc.h>
typedef struct Node
{
struct Node *prior;
struct Node *next;
int num;
}Node;
Node *createNode(int value)
{
Node *p=(Node *)malloc(sizeof(Node));
p->num=value;
p->next=p->prior=NULL;
return p;
}
Node *create_empty_list()
{
return createNode(0);
}
Node *insert(Node *head,int num)
{
Node *p2,*p;
p2=head;
p=createNode(num);
if(head->next==NULL)// 如果为空链表的话
{
head->next=p;
p->next=NULL;
p->prior=NULL;
head->prior=p;
}
else
{
/*while(p2->next!=NULL) //如果不是空链表,遍历得到最后一个节点
{
p2=p2->next;
}
p2->next=p;
p->next=NULL;
p->prior=p2;
head->prior=p;*/
head->next->prior=p;
p->prior=NULL;
p->next=head->next;
head->next=p;
}
}
void output(Node *h)
{
Node *l;
l=h->next;
while(l!=NULL)
{
printf("%d\n",l->num);
l=l->next;
}
}
int list_len(Node *head)
{
int length=0;
Node *p;
p=head->next;
while(p!=NULL)
{
length++;
p=p->next;
}
head->num=length;
return length;
}
Node *index_list(Node *head,int number)
{
Node *p;
p=head->next;
while(p != NULL && p->num != number)
{
p = p->next;
}
if(p->num == number)
{
return p;
}
else
return NULL;
}
Node *delete_node(Node *head,int number)
{
Node *p;
p=index_list(head,number);
if(p->prior == NULL)
{
head->next=p->next;
}
else
p->prior->next=p->next;
}
int main(int argc, char *argv[])
{
Node *head,*p1;
head = create_empty_list(); //创建空链表
insert(head,11); //插入数据
insert(head,19);
insert(head,7);
insert(head,6);
insert(head,34);
insert(head,56);
insert(head,67);
insert(head,78);
insert(head,13);
insert(head,15);
insert(head,8);
printf("有%d个数据\n",list_len(head));
p1 = index_list(head,78);
if(p1== NULL) return 0;
printf("找到的数据是%d\n",p1->num);
delete_node(head,8);
output(head);
return 0;
}

