| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 745 人关注过本帖
标题:删除问题
只看楼主 加入收藏
beyondlyf
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-5-8
收藏
 问题点数:0 回复次数:0 
删除问题
#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) 一段中算法是不是有错误,运行时好像老是不太对.
搜索更多相关主题的帖子: int const 删除 std void 
2008-06-02 11:39
快速回复:删除问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018731 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved