#include"stdio.h"
typedef struct Node
{
short a;
int b;
short c;
int d;
}NODE;
typedef struct MapNode//没有空间,没法赋值
{
NODE f;//这样就可,因为已经存在
struct MapNode* next;//struct MapNode next;加入不加*,是不对的。定义本身类型算不出自身内存有多大的。
}MAP;
MAP *head;
MAP* p;
int Add()
{
MAP *New;
New = (MAP*)malloc(sizeof(MAP));
printf("输入个样式:学号 性别 姓名\n");
scanf("%d", &New->f.a);
getchar();
scanf("%c", &New->f.b);
getchar();
scanf("%s", New->f.c);
getchar();
scanf("%s", New->f.d);
getchar();
New->next=null;//将New的下一个结点赋值为空
p->next = New;//p是尾结点,现在将New插入到尾结点后面,New就成了尾节点
p = New;//然后把New赋值成尾结点。尾结点更像是一个称号,人员一直流动,但是尾结点不动。
return 0;
}
int del(int linkID)
{
MAP* pc, * pb;
pb = head;
pc = head->next;
while (pc!=NULL && pc->f.b!=linkID)//找到要删除的节点的位置
{
pb = pc;//不是要找到的节点,pb跟进,pb和pc是一前一后的关系,pb在前
pc = pc->next;//pc往后走一步
}
if (pc->f.b == linkID)
{
pb->next = pc->next;
free(pc);
}
else
{
printf("不存在!\n");
}
return 0;
}
int main()
{
//int a;
//struct MapNode b;
//struct MapNode *p2;
//int* p;
//p = &a;
//p2 = &b;
head = (MAP*)malloc(sizeof(MAP));
head->f.a = 0;
head->f.b = 0;
head->f.c = 0;
head->f.d = 0;
}
网友评论