C语言(链表)
来源:互联网 发布:无限网络解码器 编辑:程序博客网 时间:2024/05/18 09:03
C语言(链表)
#include <stdio.h>
#include <stdlib.h>typedef struct _Student{
int number;//数据域
struct _Student *next;//指针域
}Student;
int main(int argc, const char * argv[]) {
//数据结构:计算机存储和组织数据的一种方式
//常用的数据结构:队列,堆,栈,二叉树,链表
//堆:动态的存储区域
//链表:重要的数据结构,动态的分配存储空间,插入和删除数据非常方便。但是他不能快速的访问某个数据。
#pragma mark - 静态链表
// Student student1,student2,student3;
// Student *head;
// //存储数据
// student1.number = 111;
// student2.number = 222;
// student3.number = 333;
// //链接
// head = &student1;
// student1.next = &student2;
// student2.next = &student3;
// student3.next = NULL;
//
//
// Student *p = head;
//
// while (p != NULL) {
// printf("%d\n",(*p).number);
// p = p ->next;
//
// }
#pragma mark - 动态链表
// Student *head,*p1,*p2;
//
// head = NULL;
// p1 = (Student *)malloc(sizeof(Student));
// printf("请用户输入学号:");
// scanf("%d",&p1 ->number);
// p2 = p1;
//
//
// while (p1 ->number != 0) {
// if (head == NULL) {
// head = p1;//p1作为头指针
// }else{
// p2 ->next = p1;//p1作为下一个结点
//
// }
// p2 = p1;
//
// p1 = (Student *)malloc(sizeof(Student));
// printf("请输入下一个学号:");
// scanf("%d",&p1 ->number);
//
// }
//
// p2 ->next = NULL;
//
// Student *pa = head;
// while (pa != NULL) {
// printf("%d\n",pa ->number);
// pa = pa ->next;
// }
/*
现有一个教务系统,根据同学的信息进行相关操作:
1.某个同学基本信息结构体(包括:姓名,学号,密码,成绩(假设该学生只有语文成绩)信息)
2.输入学号密码登陆(提示相关错误信息)
3.登陆成功后:实现以下功能:查看成绩,录入新的成绩(假设修改语文成绩),修改密码,退出登陆
//可以设置多个学生,要求功能的连贯
*/
ClassStudent student1 = {"lili", 11, "1", 55};
ClassStudent student2 = {"kiki", 22, "2", 77};
ClassStudent student3 = {"tom", 33, "3", 99};
ClassStudent students[3] = {student1, student2, student3};
welcome();
int success;
do {
success = loginSucess(students);
} while (success < 0);
do {
indicatorOfChoice();
int choiceNumber = 0;
printf("input choice number:");
scanf("%d",&choiceNumber);
switch (choiceNumber) {
case 1:
checkOfGrade(success, students);
break;
case 2:
inputNewScore();
break;
default:
break;
}
} while (1);
return 0;
}
创建C File文件
.h文件
typedef struct _ClassOfStudent{
char *name;
int number;
char *password;
int score;
}ClassStudent;
void welcome();
int loginSucess(ClassStudent students[3]);
void indicatorOfChoice();
void checkOfGrade(int index, ClassStudent students[3]);
void inputNewScore();
.c文件
#include <stdlib.h>
#include <string.h>
void welcome(){
printf("❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️\n");
printf(" 欢迎登陆教务系统\n");
printf("❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️\n");
}
void indicatorOfChoice(){
printf("****************\n");
printf(" 1.查看成绩\n");
printf(" 2.录入新的成绩\n");
printf(" 3.修改密码\n");
printf(" 4.退出登陆\n");
printf("****************\n");
}
int loginSucess(ClassStudent students[3]){
int number = 0;
int success = -1;//默认-1表示未登陆成功
char *password = malloc(40);
printf("input number:");
scanf("%d",&number);
printf("inPut password:");
scanf("%s",password);
for (int i = 0; i < 3; i ++) {
if ((number == students[i].number) && (strcmp(password, students[i].password) == 0) ) {
printf("登陆成功\n");
success = i;
break;
}
}
if (success == -1) {
printf("登陆失败\n");
}
return success;
};
//查看成绩
void checkOfGrade(int index, ClassStudent students[3]){
printf("成绩:%d\n",students[index].score);
};
//录入新成绩
void inputNewScore(){
printf("录入");
};
- 链表(C语言)
- 链表(C语言)
- C语言(链表)
- 链表(C语言)
- 链表(C语言数据结构)
- 链表(C语言实现)
- C语言(一)C语言格式
- C语言笔记(C++)
- c语言-报数问题(链表)
- C语言实现头插法(链表)
- 栈的C语言实现(链表)
- C语言基础(九)- 链表
- C语言高级篇(数据结构) --- 链表
- C语言之旅(11)链表
- c语言 链表
- c 语言 链表
- C语言:链表
- C语言:链表
- HDU 1874 畅通工程续
- 第三届山东省ACM The Best Seat in ACM Contest
- javaweb学习总结(十六)——JSP指令
- Struts2注解配置之@Results和@Result(三)
- String转换成json格式(一):net.sf.json.JSONObject
- C语言(链表)
- 基于Spark MLlib平台的协同过滤算法---电影推荐系统
- 剑指Offer Java版 基础知识1
- 第三届山东ACM Pick apples
- JavaWeb学习总结(十七)——JSP中的九个内置对象
- 那天的面试题
- 微信、支付宝支付集成--Ping++支付接入步骤-iOS版
- 计算机网络——链路层
- Struts2注解配置之@Namespace(四)