删除问题
#include<iostream>using namespace std;
const int MAXSIZE=100;
const int SIZE=10;
typedef struct
{int data[MAXSIZE];
int last;}SeqList;
SeqList *Init_SeqList(void)
{SeqList *l;
l=(SeqList *)malloc(sizeof(SeqList));
l->last=-1;
return l;}
void Creat(SeqList *l)
{cout<<"Please input "<<SIZE<<" numbers:"<<endl;
int x;
while(l->last<SIZE-1)
{cin>>x;
l->last++;
l->data[l->last]=x;}}
void Insert(SeqList *l,int x,int i)
{if(i>l->last+1||i<=0)cout<<"Attemp to insert at a wrong location!"<<endl;
else{l->last++;
for(int j=l->last;j>i-1;j--)l->data[j]=l->data[j-1];
l->data[i-1]=x;
cout<<"Insert Successfully!"<<endl;
for(i=0;i<=l->last;i++)
cout<<l->data[i]<<" ";
cout<<endl;}}
void Delete(SeqList *l,int i)
{if(i-1>l->last||i-1<0)cout<<"Delete wrong!"<<endl;
else{
for(int j=i;j<=l->last;j++)l->data[j-1]=l->data[j];
l->last--;
cout<<"Delete Successfully!"<<endl;
for(i=0;i<=l->last;i++)
cout<<l->data[i]<<" ";
cout<<endl;}}
void Search(SeqList *l,int x)
{int flag=0;
for(int i=0;i<l->last+1;i++)
if(l->data[i]==x){cout<<"The number's location is:"<<i+1<<endl;flag=1;}
if(flag!=1)cout<<"Not found!"<<endl;}
#include"类型声明.h"
int main()
{SeqList *L;
L=Init_SeqList();
Creat(L);
int F;
int P;
cout<<"Please input a number and the place wanted to insert:"<<endl;
cin>>F>>P;
Insert(L,F,P);
cout<<"Please input the location of the number you want to delete:"<<endl;
cin>>F;
Delete(L,P);
cout<<"Please input the number you want to search:"<<endl;
cin>>F;
Search(L,F);}
void Delete(SeqList *l,int i) 一段中算法是不是有错误,运行时好像老是不太对.