//初始链表为空 List MakeEmpty(List L){ while (L -> Next != NULL) L -> element = 0; return L; } //检查链表是否为空 intIsEmpty(List L){ if (L -> Next == NULL) return1; return0; } //出栈 voidDelete(List L){ Position position, tempCell; tempCell = L -> Next; position = tempCell -> Next; L -> Next = position; position -> previous = L; free(tempCell); } //入栈 voidInsert(int x, List L){ Position position; position = malloc(sizeof(*L)); if (position == NULL) return; position -> element = x; position -> Next = L -> Next; L -> Next = position; } //删除一个链表 voidDeleteList(List L){ while (L -> Next != NULL) free(L -> Next); return; } //创建一个链表并返回头结点 Position Header(){ Position L = malloc(sizeof(*L)); if (L == NULL) returnNULL; L -> Next = NULL; return L; } //返回第一个元素的位置 Position First(List L){ }
//遍历栈输出里面内容 voidShowStackInfo(List L){ while(L != NULL && L -> Next != NULL) { printf("%d ", L -> Next -> element); L = L -> Next; } return; }
intmain(){ List L = Header(); Insert(10, L); Insert(8, L); Insert(6, L); Insert(4, L); Insert(2, L); Insert(0, L); ShowStackInfo(L); }