XianFukai 2022-03-24 12:37 采纳率: 100%
浏览 25
已结题

为什么我这个程序输出有问题

#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;
}

  • 写回答

1条回答 默认 最新

  • 春休夏末 2022-03-24 13:12
    关注

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月2日
  • 已采纳回答 3月25日
  • 创建了问题 3月24日

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM