#include <iostream>
#include <stdlib.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct LNode
{
int data;
struct LNode *next;
}LNode;
LNode* createLinkList() //创建的链表
{
LNode *head;
head=(LNode*)malloc(sizeof(LNode));
head->next=NULL;
int num;
cout<<"请问元素个数是:\n";
cin>>num;
cout<<"请输入您的元素:\n";
for(int i=0;i<num;i++) //tou插法插入链表
{
LNode *p=(LNode*)malloc(sizeof(LNode));
p->next=head->next;

这段代码展示了如何在C++中创建一个链表并找到链表中的最大值和最小值。首先定义了一个链表节点结构,然后通过`createLinkList`函数输入元素构建链表。接着,`getMax`和`getMin`函数遍历链表,分别返回最大值和最小值的节点。最后,在`main01`函数中调用这些函数并输出结果。
最低0.47元/天 解锁文章
2540

被折叠的 条评论
为什么被折叠?



