double list

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define ITYPE int
#define EMPTY 0
typedef struct Note
{
 struct Note *next;
 struct Note *prev;
 ITYPE data;
}note;
typedef struct List
{
 note *head;
}list;
void Chack_List(list *l)
{
 if(NULL == l) {
  printf("no list!\n");
  exit(0);
 }
}
void Chack_Note(note *n)
{
 if(NULL == n) {
  printf("no note!\n");
  exit(0);
 }
}
void Init_List(list *l)
{
 Chack_List(l);
 l->head->next = NULL;
 l->head->prev = NULL;
}
note *Create_Note()
{
 note *new_note = (note *)malloc(sizeof(note));
 Chack_Note(new_note);
 new_note->next = NULL;
 new_note->prev = NULL;
 return new_note;
}
note *The_Last_Note(list *l)
{
 Chack_List(l);
 note *p = l->head;
 while(p->next != NULL) {
  p = p->next;
 }
 return p;
}
int Note_Num(list *l)
{
 Chack_List(l);
 int num = 0;
 note *p = l->head;
 while(p->next != NULL) {
  num++;
  p = p->next;
 }
 return num;
}
void Add_End_Note(list *l, ITYPE x)
{
 Chack_List(l);
 note *n = Create_Note();
 n->data = x;
 note *the_last_note = The_Last_Note(l);
 the_last_note->next = n;
 n->prev = the_last_note;
}
void Add_First_Note(list *l, ITYPE x)
{
 Chack_List(l);
 note *n = Create_Note();
 n->data = x;
 note *p = l->head->next;
 l->head->next = n;
 n->prev = l->head;
 n->next = p;
 if(p != NULL) {
  p->prev = n;
 }
}
ITYPE Delete_End_Note(list *l)
{
 Chack_List(l);
 Chack_Note(l->head->next);
 note *p = The_Last_Note(l)->prev;
 ITYPE data = p->next->data;
 free(p->next);
 p->next = NULL;
 return data;
}
ITYPE Delete_First_Note(list *l)
{
 Chack_List(l);
 Chack_Note(l->head->next);
 note *p = l->head->next->next;
 ITYPE data = l->head->next->data;
 free(l->head->next);
 if(p != NULL) {
  p->prev = l->head;
 }
 l->head->next = p;
 return data;
}
void Clear_List(list *l)
{
 Chack_List(l);
 while(l->head->next != NULL) {
  Delete_First_Note(l);
 }
 printf("clear over!\n");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值