线性表按序号查找(指出错误,谢谢)
#include"stdafx.h"#include<iostream>usingnamespacestd;#defineMaxsize100typedefintElem...
#include"stdafx.h"
#include<iostream>
using namespace std;
#define Maxsize 100
typedef int ElemType;
typedef struct
{
ElemType elem[Maxsize];
int last;
}Seqlist;
int Locate(SeqList L,ElemType e)
{
i=0;
while(i<=L.last)&&(L.elem[i]!=e)
printf("%d,%d",i,e);
i++;//printf("%d,%d",i,e);
if(i<=last) return(i+1);
else return(-1);
}
int main(void)
{
int e,i,a,b;
SeqList L;
printf("\n请输入要查找的节点序号:\n");
scanf("%d", &b);
e = Locate(SeqList L,ElemType e);
printf("\n您所查询节点在第%d个位置\n", e);
printf("\n");
system("PAUSE");
} 展开
#include<iostream>
using namespace std;
#define Maxsize 100
typedef int ElemType;
typedef struct
{
ElemType elem[Maxsize];
int last;
}Seqlist;
int Locate(SeqList L,ElemType e)
{
i=0;
while(i<=L.last)&&(L.elem[i]!=e)
printf("%d,%d",i,e);
i++;//printf("%d,%d",i,e);
if(i<=last) return(i+1);
else return(-1);
}
int main(void)
{
int e,i,a,b;
SeqList L;
printf("\n请输入要查找的节点序号:\n");
scanf("%d", &b);
e = Locate(SeqList L,ElemType e);
printf("\n您所查询节点在第%d个位置\n", e);
printf("\n");
system("PAUSE");
} 展开
展开全部
//不要#include"stdafx.h"
#include<iostream>
using namespace std;
#define Maxsize 100
typedef int ElemType;
typedef struct
{
ElemType elem[Maxsize];
int last;
}SeqList;//L为大写
int Locate(SeqList L,ElemType e)
{
int i=0; //加入int
while((i<=L.last)&&(L.elem[i]!=e))//少括号
printf("%d,%d",i,e);
i++;//printf("%d,%d",i,e);
if(i<=L.last) return(i+1);//L.
else return(-1);
}
int main(void)
{
int e,i,a,b;
SeqList L;
printf("\n请输入要查找的节点序号:\n");
scanf("%d", &b);
e = Locate(L,e); //传值方式不正确
printf("\n您所查询节点在第%d个位置\n", e);
printf("\n");
system("PAUSE");
}
编译通过但正确性没保证
#include<iostream>
using namespace std;
#define Maxsize 100
typedef int ElemType;
typedef struct
{
ElemType elem[Maxsize];
int last;
}SeqList;//L为大写
int Locate(SeqList L,ElemType e)
{
int i=0; //加入int
while((i<=L.last)&&(L.elem[i]!=e))//少括号
printf("%d,%d",i,e);
i++;//printf("%d,%d",i,e);
if(i<=L.last) return(i+1);//L.
else return(-1);
}
int main(void)
{
int e,i,a,b;
SeqList L;
printf("\n请输入要查找的节点序号:\n");
scanf("%d", &b);
e = Locate(L,e); //传值方式不正确
printf("\n您所查询节点在第%d个位置\n", e);
printf("\n");
system("PAUSE");
}
编译通过但正确性没保证
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询