| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 802 人关注过本帖
标题:实现顺序表各种基本运算
只看楼主 加入收藏
huangshengql
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2013-3-20
结帖率:71.43%
收藏
已结贴  问题点数:5 回复次数:1 
实现顺序表各种基本运算
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define maxsize 20
typedef int ElemType;
typedef struct SeqList
{
    ElemType elem[maxsize];
    int length;
}SeqList;
int Init_SeqList(SeqList &L)
{
    L.length=0;
    return 1;
}
int Locate_SeqList(SeqList &L,int x)
{
    int i=0;
    while(i<L.length&&L.elem[i]!=x)
        i++;
    if(i>=L.length)
    {    printf("顺序表中不存在该过元素!\n");
    return 0;
    }
    else return i+1;
}
int Insert_SqeList(SeqList &L,int i, int x)
{
    int j;
    if(L.length>=maxsize)
    {
        printf("顺序表已满,无法进行插入操作!");
        return 0;
    }
    if(i<0||i>L.length+1)
    {
        printf("插入位置不对!");
        return 0;
    }
    for(j=L.length-1;j>=i-1;j--)
    {
        L.elem[j+1]=L.elem[j];
        L.elem[i-1]=x;
        L.length++;
        return 1;
    }
    int Delete_SeqList(SeqList &L,int i)
    {
        int j;
        if((i<1)||(i>L.length))
        {
            printf("删除位置不正确!");
            return 0;
        }
        for(j=i;j<L.length;j++)
            L.elem[j-1]=L.elem[j];
        L.length--;
        return 1;
    }
    int Display_SeqList(SeqList L)
    {
        int i;
        for(i=0;i<L.length:i++)
            printf("%d",L.elem[i]);
        return 1;
    }
    void main()
    {
        SeqList L;
        ElemType e,x;
        int i=1,k,j;
        Init_SeqList(L)
            printf("初始化\n建立顺序表如下:\n"):
        Insert_SeqList(L,1,1);
        Insert_SeqList(L,2,2);
        Insert_SeqList(L,3,3);
        Insert_SeqList(L,4,4);
        Displaly_SeqList(L);
        printf("\n");
        while(i<3)
        {
            printf("\n    主菜单     \n");
            printf("1  查找指定元素   \n");
            printf("2  插入元素到指定位置   \n");
            printf("3  删除某一指定位置元素  \n");
            printf("0  结束程序  \n");
            printf("-------------------------------------\n");
            printf("请输入你要选择的菜单号<1,2,3,0>:");
            scanf("%d",&i);
            switch(i)
            {
            case 1:
                printf("请输入查找元素:");
                scanf("%d",&x);
                j=Locate_SeqList(L,x);
                if(j!=0)
                    printf("指定元素位置=%d\n",j);
                break;
            case 2:
                printf("请输入插入元素位置:");
                scanf("%d",&k);
                printf("请输入插入元素值:");
                scanf("%d",&x);
                j=Insert_SeqList(L,k,x);
                if(j!=0)
                {
                    printf("插入后的顺序如下所示\n"):
                Display_SeqList(L);
                printf("\n");
                }
                break;
            case 3:
                printf("请输入删除元素的位置:");
                scanf("%d",&k);
                j=Delete_SeqList(L,k);
                if(j!=0)
                {
                    printf("删除后顺序表如下所示\n");
                    Display_SeqList(L);
                    printf("\n");
                }
                    break;
            case 0:
                exit(0);
                break;
            default:
                printf("输入有误!");
                }
            }
        }
编译出现:
ompiling...
shiyan.cpp
E:\C C++\shiyan.cpp(48) : error C2601: 'Delete_SeqList' : local function definitions are illegal
E:\C C++\shiyan.cpp(61) : error C2601: 'Display_SeqList' : local function definitions are illegal
E:\C C++\shiyan.cpp(68) : error C2601: 'main' : local function definitions are illegal
E:\C C++\shiyan.cpp(131) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

shiyan.obj - 4 error(s), 0 warning(s)
搜索更多相关主题的帖子: 元素 include return 
2013-05-12 14:46
hebiaofu
Rank: 2
等 级:论坛游民
帖 子:6
专家分:21
注 册:2013-5-9
收藏
得分:5 
括号不匹配
2013-05-15 17:25
快速回复:实现顺序表各种基本运算
数据加载中...
 
   



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

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