单链表的基本操作

本文通过C++代码详细介绍了如何实现单链表的创建、显示、计数、增加、删除和修改等基本操作。代码中定义了结构体`Student`表示链表节点,并提供了相应的函数实现各个功能,最后在`main`函数中展示了这些操作的使用示例。
摘要由CSDN通过智能技术生成

#include<bits×dc++.h>
using namespace std;

//创建结点
typedef struct node
{
int age;
char name[20];
struct node *next;
}Student;

//创建链表
Student * creatList(int n)
{
Student * head = new Student;
Student * pre = head;
for(int i = 0;i < n;i++)
{
printf(“第%d个”,i + 1);
Student * p = new Student;
cin >> p -> age;
cin >> p -> name;
pre -> next = p;
pre = p;
}
return head;
}

//查找链表
void display(Student * head)
{
Student * p = head;
p = p -> next;
while(p != NULL)
{
cout << p -> name << “,” << p -> age << endl;
p = p -> next;
}

}

//求链表的结点个数
int count(Student * head)
{
int i = 0;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值