#include<stdio.h>
#include<stdlib.h>
#define ERROR NULL
typedef int ElemType;
typedef struct LNode *PtrToLNode;
typedef struct LNode { //对节点的定义
int Date;
struct LNode *next;
}LNode;
typedef PtrToLNode List;
typedef PtrToLNode Postion;
List MakeList(int X) { //初始化创建一个单链表
List L;
L = (List)malloc(sizeof(struct LNode));
L->Date = X;
L->next = NULL;
return L;
}
int ListLength(List L) { //求单链表的长度
int j = 0;
List p = L;
while (p) {
p = p->next;
j++;
}
return j;
}
void DisplayList(List L) { //遍历链表的元素
List p = L;
printf("遍历单链表: ");
while (p) {
printf("%d ", p->Date);
p = p->next;
}
}
void InsertListend(List L, ElemType X) { //使用尾插法将元素插入到链表最后一个位置
List p = L, s;
s = (List)malloc(sizeof(struct LNode));
s->Date = X;
s->next = NULL;
if (L == NULL) {
L = s;
}
while (p->next) {
p = p-&
单链表的基本操作(全)
最新推荐文章于 2024-04-19 17:19:21 发布