c语言的学习秘籍之链表
2018-06-18 04:12:11来源:未知 阅读 ()
刚翻出来的作品,有点低级,但希望能起到作用:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#define SLEEP() asm("sleep")
struct student *head;
struct student
{
int a;
int b;
struct student * next;
};
int n;
void add()
{
printf("请输入俩个你要储存的数字\n");
struct student *p1, *p2;
p1 = p2 = (struct student *)malloc(sizeof(struct student));
head->next = p1;
scanf_s("%d%d", &p2->a, &p2->b);
while (p2->a != NULL)
{
n = n + 1;
p1->next = p2;
p1 = p2;
p2 = (struct student *)malloc(sizeof(struct student));
scanf_s("%d%d", &p2->a, &p2->b);
}
p1->next = NULL;
}
void print(struct student*head)
{
if (head->next != NULL)
{
struct student *p1;
p1 = (struct student *)malloc(sizeof(struct student));
p1 = head->next;
while (p1 != NULL)
{
printf("%d\t%d\n", p1->a, p1->b);
p1 = p1->next;
}
}
else printf("无法执行!!!");
}
void look()
{
if (head->next != NULL)
{
struct student *p1;
p1 = (struct student *)malloc(sizeof(struct student));
p1 = head->next;
int m = 1;
printf("请输入你要查找的位置\n");
int a;
scanf_s("%d", &a);
while (m != a)
{
m = m + 1;
p1 = p1->next;
}
printf("%d\t%d\n", p1->a, p1->b);
}
else printf("无法执行!!!");
}
void gai()
{
if (head->next!=NULL)
{
struct student *p1;
p1 = (struct student *)malloc(sizeof(struct student));
p1 = head->next;
int m = 1;
printf("请输入你要修改的位置\n");
int a;
scanf_s("%d", &a);
while (m != a)
{
m = m + 1;
p1 = p1->next;
}
scanf_s("%d%d", &p1->a, &p1->b);
}
else printf("无法执行!!!");
}
void shan()
{
if (head->next != NULL)
{
struct student *p1;
p1 = (struct student *)malloc(sizeof(struct student));
p1 = head;
int m = 1;
printf("请输入你要删除的位置\n");
int a;
scanf_s("%d", &a);
while (m != a)
{
m = m + 1;
p1 = p1->next;
}
p1->next = p1->next->next;
}
else printf("无法执行!!!");
}
void zeng()/************************************************************************************/
{
if (head->next!=NULL)
{ struct student *p1, *p2, *p3;
p1 = (struct student *)malloc(sizeof(struct student));
p1 = head->next;
while (p1->next != NULL)
{
printf("%d\t%d\n", p1->a, p1->b);
p1 = p1->next;
}
printf("请输入你要储存的数据\n");
p2 = p3 = (struct student *)malloc(sizeof(struct student));
p1->next = p2;
scanf_s("%d%d", &p3->a, &p3->b);
while (p3->a!=0)
{
n = n + 1;
p2->next = p3;
p2 = p3;
p3 = (struct student *)malloc(sizeof(struct student));
scanf_s("%d%d", &p3->a, &p3->b);
}
p2->next = NULL;
}
else printf("无法执行!!!");
}
int main()/*******************************************************************************************/
{
head = (struct student *)malloc(sizeof(struct student));
head->next = NULL;
n = 0;
int a=1;
printf("***************************************************************************************************************\n");
printf("* <<输入请按1>> <<输出请按2>> *\n");
printf("* <<增加请按3>> <<删除请按4>> *\n");
printf("* <<修改请按5>> <<退出请按0>> *\n");
printf("请选择接下来的功能\n");
while (a!=0)
{
scanf_s("%d", &a);
switch (a)
{
case 0:break;
case 1: add(); break;
case 2: print(head); break;
case 3: zeng(); break;
case 4:shan(); break;
case 5:gai(); break;
default:printf("孩子不要玩了!!!"),Sleep(1000),system("cls"),printf("爸爸永远爱你!!\n");
}
if (a != 0){
printf("请选择接下来的功能\n");
}
}
printf("等待两分钟有惊喜哦!!!!\n");
Sleep(20000);
printf("让你等你就等,你傻了吧!!!sb\n");
return 0;
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 关于各种不同开发语言之间数据加密方法(DES,RSA等)的互通的 2020-06-07
- 如何0基础学习C/C++? 2020-06-06
- C语言程序结构 2020-05-31
- vtk学习记录(三)——初识vtkRenderer 2020-05-16
- 每日干货丨C++语言主流开发工具推荐! 2020-04-28
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash