| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 476 人关注过本帖
标题:请各位帮帮忙:看看为什么不能运行?
只看楼主 加入收藏
computer_virus
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-4-17
收藏
 问题点数:0 回复次数:3 
请各位帮帮忙:看看为什么不能运行?
#include<iostream>
using namespace std;
typedef int ElemType;
const int Maxsize=10;
typedef struct Sqlist
{
    ElemType *elem;
    int length;
    int listsize;
}Sqlist;
void InitSqlist(Sqlist &L)
{
    L.elem=new ElemType[Maxsize];
    if(L.elem==0) exit(1);
    L.length=0;
    L.listsize=Maxsize;
}
void DestroySqlist(Sqlist &L)
{
    delete[]L.elem;
    L.elem=0;
    L.length=L.listsize=0;
}
void ClearSqlist(Sqlist &L)
{
    L.length=0;
}
int Sqlistlength(Sqlist& L)
{
    return L.length;
}
int SqlistCapacity(Sqlist &L)
{
    return L.listsize;
}
int SqlistEmpyt(Sqlist &L)
{
    return L.length=0;
}
void EnlargeSqlist(Sqlist &L)
{
    ElemType*newbase=new ElemType[2*L.listsize];
    for(int i=0;i<L.length;i++)
    newbase[i]=L.elem[i];
    delete[]L.elem;
    L.elem=newbase;
    L.listsize=2*L.listsize;    
}
void InsertSqlistAtNoi(Sqlist &L,int i,ElemType x)//Inserts an element in the ith position x
{
    if(i<1||i>L.length) return ;
    if(L.length==L.listsize)
    EnlargeSqlist(L);
    int j=L.length-1;
    while(j>=i-1)
    {
    L.elem[j+1]=L.elem[j];
    j--;
    L.length++;
    }
void DisplaySqlist(Sqlist &L)
{
    for(int i=0;i<L.length;i++)
        cout<<L.elem[i]<<" ";
        cout<<endl;
}
int SqlistLocateNoi(Sqlist &L,int i,ElemType &x)//Searches the ith data element
{
    if(i<1||i>L.length)
    cout<<"Searches the position not to be illegal !"<<endl; return 0;
    x=L.elem[i-1]; return 1;
}
int SqlistLocatex(Sqlist &L,ElemType x)//The search value is x data element
{
    int i=1;
    while(i<=L.length&&L.elem[i-1]!=x)
    i++;
    if(i<=L.length) return i;else return 0;
}
void test()
{
    Sqlist L;
    InitSqlist(L);
    ElemType x;
    int i;
    cout<<"please enter 15 numbers:"<<endl;
    for(i=0;i<15;i++)
    {
    cin>>x;
    InsertSqlistAtNoi(L,L.length,x);
    }
    cout<<"now L is:"<<endl;
    DisplaySqlist(L);
    cout<<"Please input the serial number which must search :"<<endl;
    cin>>i;
    if(SqlistLocateNoi(L,i,x))
    cout<<"This is the"<<i<<"element value is :"<<x<<endl;
    else cout<<"There is no"<<i<<"element,Has surpassed 1 and"<<L.length<<"scope!"<<endl;
    cout<<"Please input the serial number which must search :"<<endl;
    cin>>i;
    if(SqlistLocateNoi(L,i,x))
    cout<<"This is the"<<i<<"element value is:"<<x<<endl;
    else cout<<"There is no"<<i<<"element,Has surpassed 1 and"<<L.length<<"scope!"<<endl;
    cout<<"Please input the serial number which must search:"<<endl;
    cin>>i;
    if(SqlistLocateNoi(L,i,x))
    cout<<"This is the"<<i<<"element value is :"<<x<<endl;
    else cout<<"There is no"<<i<<"element,Has surpassed" <<L.length<<"scope!"<<endl;
    cout<<"Please input the element which must search :"<<endl;
    cin>>x;
    i=SqlistLocatex(L,x);
    if(i)
    cout<<x<<"is this"<<i<<"element"<<endl;
    else cout<<"Does not have the value is "<<x<<"elements"<<endl;
    cout<<"Please input the element which must search:"<<endl;
    cin>>x;
    i=SqlistLocatex(L,x);
    if(i)
    cout<<x<<"is this"<<i<<"element"<<endl;
    else cout<<"Does not have the value is"<<x<<"elements"<<endl;
    cout<<"Please input the element which must search:"<<endl;
    cin>>x;
    i=SqlistLocatex(L,x);
    if(i)
    cout<<x<<"is this"<<i<<"element"<<endl;
    else cout<<"Dose not have the valude is"<<x<<"elements"<<endl;
}
int main()
{
    test();
    return 0;
}
搜索更多相关主题的帖子: 运行 
2008-04-17 17:11
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
发一下错误提示吧,看我能不能看出是什么意思

i like linux...
2008-04-17 20:48
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
把程序写清楚点吧..没注释不可怕..只要能看懂就好

学习需要安静。。海盗要重新来过。。
2008-04-17 23:11
tymstill
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2008-1-28
收藏
得分:0 
void InsertSqlistAtNoi(Sqlist &L,int i,ElemType x)//Inserts an element in the ith position x
{
    if(i<1||i>L.length) return ;
    if(L.length==L.listsize)
    EnlargeSqlist(L);
    int j=L.length-1;
    while(j>=i-1)
    {
    L.elem[j+1]=L.elem[j];
    j--;
    L.length++;
    }

while循环少了一个"}"
2008-04-18 08:49
快速回复:请各位帮帮忙:看看为什么不能运行?
数据加载中...
 
   



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

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