赞
踩
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
-
- #define MAXSIZE 10
- #define OK 1
- #define ERROR 0
- #define T 1
- #define F -1
-
- typedef int Status;
- struct Student {
- int id;
- };
-
- typedef struct Dlist {
- Student data;
- struct Dlist* next;
- }Dlist,*Zdlist;
-
- //创建
- Status Cj_List(Zdlist& L) {
- L = (Zdlist)malloc(sizeof(Student));
- if (L) {
- L->next = NULL;
- printf("创建成功!\n");
- return OK;
- }
- printf("创建失败!\a\n");
- return ERROR;
- }
-
- //插入
- Status Cr_List(Zdlist &L ,int i,Student e) {
- Zdlist p ,s;
- p = L;
- int j = 0; //判断是否有头结点,无头节点则创建失败。
- while (p && (j < i - 1)) {
- p = p->next;
- ++j;
- }
- if (!p || j > i - 1) {
- printf("插入失败!\a\n");
- return ERROR;
- }
- s = (Zdlist)malloc(sizeof(Student));//插入时先新建头结点
- s->next = NULL; //定义p=L用p代替L进行指针遍历,防止丢失头结点
- s->data = e;
- s->next = p->next;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。