| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:[求救]顺序表问题2
只看楼主 加入收藏
lewlay
Rank: 1
来 自:安徽
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-9-24
收藏
 问题点数:0 回复次数:0 
[求救]顺序表问题2
1.实现顺序表的各种基本操作。
#define Maxsize 100
#include <stdio.h>

typedef int elemtype;

typedef struct sqnode
{elemtype elem[Maxsize];
 int len;          /*注意这里的len代表的含义与书本上last的区别*/
}sqlist;

void create_sqlist(sqlist *L)
{int i;
 printf("Please input the len of the sqlist:");
 scanf("%d",&(*L).len);
 printf("Please input the every element of the sqlist:");
 for(i=0;i<(*L).len;i++)
    scanf("%d",&(*L).elem[i]);
 printf("Output the every element of the sqlist:");
 for(i=0;i<(*L).len;i++)
    printf("%d ",(*L).elem[i]);
 printf("\n");
}

void access_sqlist(sqlist *L,int i)
{if((i<0)||(i>(*L).len-1))
   printf("The place is not correct!\n");
 else
   printf("%d\n",(*L).elem[i]);
}

void before_after_sqlist(sqlist *L,int i)
{if((i<0)||(i>(*L).len-1))
    printf("The place is not correct!\n");
 else if(i==0)
    printf("%d\n",(*L).elem[i+1]);
 else if(i==(*L).len-1)
    printf("%d\n",(*L).elem[i-1]);
 else if((i>0)&&(i<(*L).len-1))
    printf("%d,%d\n",(*L).elem[i-1],(*L).elem[i+1]);
}

void search_sqlist(sqlist *L,int s_key)
{int m;
 for(m=0;m<(*L).len;m++)
   {if((*L).elem[m]!=s_key)
        continue;
    else
        {printf("Seaching is seccessful!\n");
     printf("The place of the search key is:%d\n",m);
     break;
    }
   }
 if(m>=(*L).len)
    printf("The sqlist has no the s_key!\n");
}

void delete_sqlist(sqlist *L,int i)
{int n;
 (*L).len--;
 for(n=i;n<(*L).len;n++)
   (*L).elem[n]=(*L).elem[n+1];
 printf("Output the every element of the sqlist:");
 for(i=0;i<(*L).len;i++)
    printf("%d ",(*L).elem[i]);
 printf("\n");
}

void insert_sqlist(sqlist *L,int i,int e)
{int m;
 (*L).len++;
 for(m=(*L).len-1;m>=i;m--)
   (*L).elem[m+1]=(*L).elem[m];
 (*L).elem[i]=e;
 printf("Output the every element of the sqlist:");
 for(i=0;i<(*L).len;i++)
    printf("%d ",(*L).elem[i]);
 printf("\n");
}
          show_sqlist(                  )
{





}
main()
{ sqlist *L;
 int i,e;
 clrscr();
 printf("\nfunction:create_sqlist\n");
 create_sqlist(L);
 show_sqlist(L);
 printf("\nfunction:access_sqlist\n");
 printf("Please input the position:");
 scanf("%d",&i);
 access_sqlist(L,i);
 show_sqlist(L);
 printf("\nfunction:before_after_sqlist\n");
 printf("Please input the position:");
 scanf("%d",&i);
 before_after_sqlist(L,i);
 show_sqlist(L);
 printf("\nfunction:search_sqlist\n");
 printf("Please input the search key:");
 scanf("%d",&e);
 search_sqlist(L,e);
 show_sqlist(L);
 printf("\nfunction:delete_sqlist\n");
 printf("Please input the delete position:");
 scanf("%d",&i);
 delete_sqlist(L,i);
 show_sqlist(L);
 printf("\nfunction:insert_sqlist\n");
 printf("Please input the insert position:");
 scanf("%d",&i);
 printf("Please input the insert element:");
 scanf("%d",&e);
 insert_sqlist(L,i,e);
 show_sqlist(L);



1。写出每个函数的功能:
create_sqlist;      
access_sqlist ;   
before_after_sqlist;
search_sqlist;
delete_sqlist ;      
insert_sqlist;
2。将上述顺序表中表元素的函数show_sqlist补充完整;
搜索更多相关主题的帖子: 顺序 
2008-09-24 09:15
快速回复:[求救]顺序表问题2
数据加载中...
 
   



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

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