#include<iostream>
#include<stdio.h>
#include<math.h>
#define NULL 0
#define LEN sizeof(struct Student)
using namespace std;
typedef struct Student
{
int length;
int num;
struct Student *next;
}Student;
typedef Student *Linklist; //头指针
void Error(char *s) //错误指示
{
std::cout << s << endl;
exit(1);
}
Student *creat(void) //创建链表
{
Student *head;
Student *p, *q;
int n = 0;
q = (Student*)malloc(LEN);
p = q;
cout << "请输入元素:" << endl;
cin >> p->num;
head = NULL;
while (p->num != 0)
{
n = n + 1;
if (n == 1)
{
head = p;
head->length = 1;
}
else
{
q->next = p;
q = p;
p = (Student*)malloc(LEN);
cin >> p->num;
head->length++;
}
}
q->next = NULL;
return head;
cout << "链表创建成功!" << endl;
}
void Insertlist(Linkl
c语言:单链表的实现(一) 创建,插入,删除,查找
最新推荐文章于 2024-01-28 21:32:36 发布