#include
#include<stdlib.h>
using namespace std;
typedef struct node{
int data;
struct node* next;
}*LinkList,node;
void initlist(LinkList &L)
{
L=(LinkList)malloc(sizeof(node));
L->next=NULL;
}
void creatlist(LinkList &L)
{
int n;
initlist(L);
LinkList p,r;
r=L;
cin>>n;
while(n>0)
{
p=(LinkList)malloc(sizeof(node));
cin>>p->data;
p->next=NULL;
r->next=p;
L=p;
n--;
}
}
int getmax(LinkList L)
{
if(L->next==NULL)
{
return NULL;
}
LinkList p;
int n;
p=L->next;
n=p->data;
while(p)
{
if(p->data>n)
{
n=p->data;
p=p->next;
}
}
return n;
}
int location(LinkList L,int n)
{
LinkList p;
p=L->next;
int i=1;
while(p&&p->data!=n)
{
p=p->next;
i++;
}
return i;
}
int main()
{
int n,i,m,k;
for(i=0;i<n;i++)
{
LinkList L,p;
initlist(L);
creatlist(L);
p=L->next;
m=getmax(L);
k=location(L,m);
cout<<"max="<<m<<" ";
cout<<"num="<<k<<endl;
}
return 0;
}
为什么我这个程序输出有问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
悬赏问题
- ¥15 BP神经网络控制倒立摆
- ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
- ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
- ¥30 Unity接入微信SDK 无法开启摄像头
- ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
- ¥20 cad图纸,chx-3六轴码垛机器人
- ¥15 移动摄像头专网需要解vlan
- ¥20 access多表提取相同字段数据并合并
- ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
- ¥20 Java-Oj-桌布的计算