#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 提建议
- 关注问题
- 邀请回答
-