单链表-姓名学号-创建/遍历/增添/删除

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Student{
    char Name[20];
    char Number[10];
    struct Student *next;
};
int Count;
struct Student *Create(){
    struct Student *pHead  = 0;
    struct Student *pEnd,*pNew;
    Count = 0;
    pEnd = pNew =(struct Student *)malloc(sizeof(struct Student));
    printf("请输入学生的姓名和学号:(姓名和学号都为0时结束录入)\n");
    scanf("%s",&pNew->Name);
    scanf("%s",&pNew->Number);
    while((strcmp("0",pNew->Number)!=0)||(strcmp("0",pNew->Name)!=0)){
        Count++;
        if(Count==1){
            pNew->next = pHead;
            pHead=pNew; 
            pEnd=pNew; 
        }
        else{
            pNew->next = 0;
            pEnd->next=pNew;
            pEnd=pNew;
        }
        pNew=(struct Student *)malloc(sizeof(struct Student));
        scanf("%s",&pNew->Name);
        scanf("%s",&pNew->Number);

    } 
    printf("\n信息录入成功\n\n"); 
    free(pNew); 
    return pHead;
} 
struct Student *AddNodeToTheHead(struct Student *pHead){
    struct Student *pNew;
    pNew = (struct Student *)malloc(sizeof(struct Student));
    printf("请输入添加到开头的学生姓名、学号:(输入cancel中止添加)\n");
    scanf("%s",&pNew->Name);
    if(strcmp("cancel",pNew->Name)==0)return pHead;
    scanf("%s",&pNew->Number); 
    pNew->next = pHead;
    pHead = pNew;
    Count++; 
    printf("\n添加到开头成功!\n\
  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值