64,666
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
#define N 100
typedef struct Node
{
int data[100];
int length;
} SeqList;
void InsertList(SeqList& L,int x,int i)
{
int j;
if (i <1||i>L.length+1)
{
cout <<"i的取值有误";
getchar();
exit(0);
}
if (L.length>=N)
{
cout <<"溢出错误";
getchar();
return;
}
for (j=L.length-1;j>=i;j--)
L.data[j+1]=L.data[j];
L.data[i]=x;
L.length++;
}
int main()
{
int a,b;
cout <<"请输入你想在增加的位置";
cin>>a;
cout <<"请输入节点的值";
cin>>b;
SeqList L;
InsertList(L,b,a);
return 0;
}
#include <iostream>
using namespace std;
#define N 100
typedef struct Node
{
int data[100];
int length;
}SeqList;
void InsertList(SeqList &L,int x,int i)
{
int j;
if(i <1||i>L.length+1)
{
cout <<"i的取值有误";
getchar();
exit(0);
}
if(L.length>=N)
{
cout <<"溢出错误";
getchar();
return;
}
for(j=L.length-1;j>=i;j--)
L.data[j+1]=L.data[j];
L.data[i]=x;
L.length++;
}
void main()
{
int a,b;
cout <<"请输入你想在增加的位置";
cin>>a;
cout <<"请输入节点的值";
cin>>b;
SeqList L;
InsertList(L,b,a);
}
#include <iostream>
using namespace std;
#define N 100
typedef struct Node //typedef重命名
{
int data[100];
int length;
} SeqList;
void InsertList(SeqList &L,int x,int i)//不要加分号
{
int j;
if(i <1||i>L.length+1)
{
cout <<"i的取值有误";
getchar();
exit(0);
}
if(L.length>=N)
{
cout <<"溢出错误";
getchar();
return;
}
for(j=L.length-1;j>=i;j--)
L.data[j+1]=L.data[j];
L.data[i]=x;
L.length++;
}
void main()
{
int a,b;
cout <<"请输入你想在增加的位置";
cin>>a;
cout <<"请输入节点的值";
cin>>b;
SeqList L;
InsertList(L,b,a); //传值,而不是指针,第一个参数是引用,不是地址
}