欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

线性表插入,删除,查询操作

程序员文章站 2022-04-05 12:58:07
...
int find(int value){
for(int i=0;i<currentP;++i){
   if(arrayOfNum[i]==value)
    return i;
}
return -1;
}

void insert(int index){
int num;
if(index<0||index>currentP)
   cout<<"position illeagle!\n";
else{
   for(int i=currentP;i>index;i--){
    arrayOfNum[i]=arrayOfNum[i-1];
   }
   printf("input insert number\n");
   cin>>num;
   arrayOfNum[i]=num;
   currentP++;
}
}

void deleteP(int index)
{
if(index>currentP||index<0)
   cout<<"delete Point illeagle!";
else
{
   for(int i=index;i<currentP;i++){
    arrayOfNum[i]=arrayOfNum[i+1];
   }
   currentP--;
}

}

void procInitial()
{
currentP=0;
cin>>n;
for(int i=0;i<n;i++){
   scanf("%d",&arrayOfNum[i]);
   currentP++;
}
}