#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdlib.h>
#include <malloc.h>
#define ITYPE int
#define EMPTY 0
#define EMPTY 0
typedef struct Note
{
struct Note *next;
struct Note *prev;
ITYPE data;
}note;
{
struct Note *next;
struct Note *prev;
ITYPE data;
}note;
typedef struct List
{
note *head;
}list;
{
note *head;
}list;
void Chack_List(list *l)
{
if(NULL == l) {
printf("no list!\n");
exit(0);
}
}
{
if(NULL == l) {
printf("no list!\n");
exit(0);
}
}
void Chack_Note(note *n)
{
if(NULL == n) {
printf("no note!\n");
exit(0);
}
}
{
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;
}
{
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 *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;
}
{
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;
}
{
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;
}
{
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;
}
}
{
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;
}
{
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;
}
{
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");
}
{
Chack_List(l);
while(l->head->next != NULL) {
Delete_First_Note(l);
}
printf("clear over!\n");
}