#include bitsstdc++husing namespace std;struct student string name; struct student next;;void printLinkstruct student head struct student p=head; whilep!=NULL coutp-name-; p=p-next; coutNULLendl;i
#include <bits/stdc++.h>
// 引入标准头文件
using namespace std;
// 使用命名空间std
struct student
{
// 定义结构体student
string name;
// 字符串类型成员name
struct student *next;
// 结构体类型指针成员next
};
// 结构体定义完毕
void printLink(struct student *head)
// 定义函数printLink,参数为结构体类型指针head
{
struct student *p=head;
// 定义结构体类型指针p,初始化为head
while(p!=NULL)
// 循环条件为p不为空
{
cout<
cout<<"4种节点插入可能"<<endl; // 输出提示信息 cout<<endl<<"1.节点插入到链表的最前面"<<endl; // 输出提示信息 stu5.name="周"; // 给结构体变量赋值 stu5.next=head; // 将stu5的next指向head head=&stu5; // 将head指向stu5 printLink(head); // 调用函数printLink,输出链表中的元素
return 0; // 返回0,结束程序 }逐句翻
AI 优化版
原文地址:https://www.cveoy.top/t/topic/drlr 著作权归作者所有。请勿转载和采集!