#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include<queue>
using namespace std;
//结点
typedef struct Lnode {
int data;
struct Lnode *next;
}Lnode, *Linklist;
//尾插
void Creatlist(Linklist &L, int &e) {
Lnode *p = new Lnode;
p->data = e;
p->next = NULL; //处理新加入节点
Lnode *cur = L;
while (cur->next != NULL) {
cur = cur->next;
}
cur->next = p;
p->next = NULL;
}
//初始化
void Initlist(Linklist &L) {
L = new Lnode;
L->next = NULL;
}
//寻找最大值
void Maxnum(Linklist &L1) {
int max = -100;
Lnode *p = L1->next;
while (p)
{
if (p->data > max) {
max = p->data;
}
p = p->next;
}
printf("%d\n", max);
}
int main() {
int n;
while (scanf("%d",&n)!=EOF) {
if (n == 0) break;
Linklist L1;
Initlist(L1);
for (int i = 0; i < n; i++) { //输入数据
int e;
cin >> e;
Creatlist(L1, e);
}
Maxnum(L1);
}
}
BJFU 230查找链表中的最大值
最新推荐文章于 2024-08-29 22:06:50 发布