2203: 最小节点(线性表)
时间限制: 1 Sec 内存限制: 128 MB提交: 243 解决: 204
题目描述
(线性表)设有一个由正整数组成的无序(向后)单链表,编写完成下列功能的算法:找出最小值结点,且打印该数值。
输入
输入长度:6
输入数据:3 2 1 4 6 8
输出
1
样例输入
6
11 14 5 6 8 9
样例输出
5
迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ab
{
int data;
ab* next;
};
int start(int n)
{
struct ab *p1,*p2;
int min=0xffff;
p1=p2=(struct ab*)malloc(sizeof(struct ab));
for(int i=0; i<n; i++)
{
if(i)p2->next=p1;
scanf("%d",&p1->data);
min=min>p1->data?p1->data:min;
p2=p1;
p1=(struct ab*)malloc(sizeof(struct ab));
}
p2->next=NULL;
return min;
}
int main()
{
int n,min;
scanf("%d",&n);
min=start(n);
printf("%d\n",min);
return 0;
}