链表实现学生信息管理系统,增删查改

很久没有写C语言了,今天突然回顾一下,就写了一个简答的单链表实现学生信息管理的增删查改,对与初学者来说可以参考!

#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
//表节点结构体
typedef struct LinkNode
{
    char stu_no[10];//学号
    char stu_name[10];//名字
    struct LinkNode *next;
}LinkNode;
//初始化链表
LinkNode* Initial_LinkList(LinkNode *&L)
{
      LinkNode *node = (LinkNode*)malloc(sizeof(LinkNode));
      node->next = NULL;
}
//向链表中插入新节点
void InsertNode(LinkNode *&L,char *stu_no,char *stu_name)
{
    if(L!=NULL)
    {
      LinkNode *node = (LinkNode*)malloc(sizeof(LinkNode));
      strcpy(node->stu_no,stu_no);
      strcpy(node->stu_name,stu_name);
      node->next = NULL;

      LinkNode *p;
      p=L;
      node->next=p->next;
      p->next=node;

    }
}
//打印链表节点信息
void printNode(LinkNode *L)
{
    LinkNode *p=L->next;
    while(p!=NULL)
    {
    printf("stu_no:%s stu_name:%s \n",p->stu_no,p->stu_name);
    p=p->next;
    }

}
//删除链表节点
void deleteNode(LinkNode *&L,char *num)
{
    LinkNode *p,*s;
    p=L;
    while(p->next!=NULL)
    {
    if(strcmp(p->next->stu_no,num)==0)
    {
        s=p->next;
        p->next=p->next->next;
        free(s);
    }
    p=p->next;
    }
}
//修改链表节点信息
void modify_Node(LinkNode *L,char *stu_no,char stu_name[])
{
    LinkNode *p;
    p=L->next;
    while(p!=NULL)
    {
        if(strcmp(stu_no,p->stu_no)==0)
        {
            strcpy(p->stu_name,stu_name);
        }
        p=p->next;
    }
}
int main()
{
    int i=0;
    LinkNode *L;
    L=Initial_LinkList(L);
    char stu_no[10],stu_name[10];

    while(i<4)
    {
        cout<<"please enter stu_no:"<<endl;
        scanf("%s",&stu_no);
        cout<<"please enter stu_name:"<<endl;
        scanf("%s",&stu_name);
        InsertNode(L,stu_no,stu_name);
        ++i;
    }
    printNode(L);
    printf("enter delete num:");
    scanf("%s",&stu_no);
    deleteNode(L,stu_no);
    printNode(L);
    printf("输入要修改的学号:");
    scanf("%s\n",&stu_no);
    printf("输入新姓名:");
    scanf("%s\n",&stu_name);
    modify_Node(L,stu_no,stu_name);
    printNode(L);
    return 0;
}

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值