lianbiao.cpp

来自「C实现的单链表」· C++ 代码 · 共 67 行

CPP
67
字号
#include<stdio.h>
#include"hanshu.h"
#define NULL 0
#define LEN sizeof(struct stu)
int n=0;
void main()
{
	int k;
	struct stu * head,* stu;
	long del_num;
	printf("创建链表:\n");
	head=creat();
	print(head);
	while(1)
	{
		printf("选择下一步操作:\n1:插入新节点\t2:删除节点\t3:链表倒置\t4:销毁链表\t5:输出文本\t0:退出\n");
		scanf("%d",&k);
		switch(k)
		{
		case 1:
			printf("\ninput the inserted number:\n");
			stu=(struct stu *)malloc(LEN);
			scanf("%ld%f",&stu->num,&stu->score);
			while(stu->num!=0)
			{
				head=in(head,stu);
				print(head);
				printf("\ninput the inserted number:\n");
				stu=(struct stu *)malloc(LEN);
				scanf("%ld%f",&stu->num,&stu->score);
			}
			break;

		case 2:
			printf("\ninput the deleted number:\n");
			scanf("%ld",&del_num);
			while(del_num!=0)
			{
				head=del(head,del_num);
				if(head==NULL)
					break;
				print(head);
				printf("input the deleted number:");
				scanf("%ld",&del_num);
			}
			break;
		
		case 3:
			head=reverse(head);
			print(head);
			break;
		case 4:
			free(head);
			exit(0);
		case 5:
			save(head);
			break;
		case 0:
			goto end;
		default:
			printf("选择错误,请重新选择.");
			break;
		}
	}
end:free(head);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?