2008秋-计算机软件基础- 实验一 参考源程序
实验一 参考源程序
// Author: Eman Lee
#include<stdio.h>
void SearchMultipleLocation(char List[],int *ListLength,char key)
{
int i;
for(i=0;i<*ListLength;i++)
{
if(List[i]==key)
printf("\nSearch %c, found, location: %d \n",key,i);
}
}
int Search(char List[],int *ListLength,char key)
{
int i;
for(i=0;i<*ListLength;i++)
{
if(List[i]==key)
return i;
}
return -1;
}
void SeqListDelete(char list[],int * listLength,int i)
{
/*删除顺序表中下标为i的元素,使得表长减1。 */
int j ;
if(*listLength==0)
printf("the list is empty!\n");
else
if (i<0 || i>*listLength-1)
printf("the position is invalid!\n");
else
{
for (j=i+1;j<=*listLength-1;j++)
list[j-1]=list[j]; /*元素前移*/
(*listLength)--; /*表长减1*/
printf("\n删除顺序表中下标为%d的元素\n",i);
}
}
void SeqListInsert(char List[],int Location,
char E,int *ListLength)
{ //ListLength=&length
int i;//循环变量
//向后移动元素,自右向左
for(i=*ListLength-1;i>=Location;i--)
{
List[i+1]=List[i];
}
List[Location]=E;//插入元素
(*ListLength)++;//表长加一
printf("\n在%d处插入元素%c\n",Location,E);
//PrintSeqList(List,*ListLength);
}
void PrintSeqList(char List[],int ListLength)
{
int i;//循环变量
//显示
printf("\n显示所有元素:\n");
for(i=0;i<=ListLength-1;i++)
printf(" %c ",List[i]);
printf("\n");
}
void main()
{
//在一维数组位置Location处插入E
char SeqList[10]={'0','1','3','2','3','4','5'};
int location;
int length=7;//表长为6
PrintSeqList(SeqList,length);
SeqListInsert(SeqList,5,'7',&length);//在位置5处插入7
PrintSeqList(SeqList,length);//显示
SeqListDelete(SeqList,&length,0);
PrintSeqList(SeqList,length);//显示
SearchMultipleLocation(SeqList,&length,'3');
location=Search(SeqList,&length,'2');
if(location>=0)
printf("found '2',loc: %d\n",location);
else
printf("search '2',not found\n ");
}
/*计算机软件基础 教材 P79, ex2
题目:设线性表存放于整形数组a[arrayLength]的前几个分量
(a[0]-a[listLength-1])中,且递增有序。试写一算法,
将元素x插入线性表适当的位置,以保持线性表的有序性。*/
#include<stdio.h>
void show(int a[],int listLength)
{
int i;
printf("\n显示所有元素:");
for(i=0;i<listLength;i++)
printf(" %d ",a[i]);
}
int insert(int a[],int arrayLength,int *ListLength,int x)
{
int i,j;
if(*ListLength==arrayLength)
return 0;/*fail*/
printf("\n插入元素%d.",x);
for(i=0;i<*ListLength;i++)
{
if(a[i]>=x)/*search successfully*/
{
for(j=*ListLength;j>i;j--)
a[j]=a[j-1];/*move*/
a[i]=x;
(*ListLength)++;
return 1;/*success*/
}
}
(*ListLength)++;
a[i]=x;
return 1;/*success*/
}
void main()
{
int array[100]={ 1,3,5,7,9};
int listLength=5;
int i;
show(array,listLength);
for(i=0;i<11;i++)
{
insert(array,100,&listLength,i);
show(array,listLength);
}
}
转载于:https://www.cnblogs.com/emanlee/archive/2007/10/16/926716.html
2008秋-计算机软件基础- 实验一 参考源程序相关推荐
- 2008秋-计算机软件基础-第四章习题参考答案 P131 ,习题6之一
Author: Eman Lee P131,第6题之一 参考答案 (1) 直接插入排序 初始状态 [53] [87 12 61 70 68 27 65 21 35 ] 第 ...
- 大学计算机基础网络配置实验报告答案,2008大学计算机基础实验报告参考答案...
实验一 请学生自己写出实验内容1.2和3其他实验的操作步骤 2.6 开始|程序|附件|画图 2.7 拖动窗口的标题栏到屏幕右上角. 2.8 将鼠标指针移至窗口的各个角和边处,适当调整大小为屏幕的1/4 ...
- 2008秋-计算机软件基础-第三章- 二叉排序树
/*--------------------------------------------------------- Title: 二叉排序树(Binary Sorting Tree) 请先阅 ...
- 计算机网络实验考试西南交大,西南交大大学计算机基础实验2参考答案
西南交大大学计算机基础实验2参考答案 (20页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 14.90 积分 大学计算机基础实验报告大学计算机基础实验报告 ...
- 微生物基础实验操作参考手册,微生物科研人必看!干货满满
关注"微生态"公众号,了解更多微生科研干货 生科云网址:https://www.bioincloud.tech 微科盟此次为广大微生态科研工作者分享微生物基础实验操作参考手册,该手 ...
- 东北大学计算机软件基础实验报告,东北大学计算机软件技术基础实验报告.pdf...
东北大学计算机软件技术基础实验报告 计算机软件技术基础实验 专 业: 学生姓名:[哈哈哈] 学 号:[哈哈哈] 实验时间:[2016 年8 月22 日] 实验一:线性表的排序与查找 #include ...
- 2008秋季-计算机软件基础-有序表合并 教材 P79, ex3
/* Author: Eman Lee */ /*计算机软件基础 教材 P79, ex3*/ #include <stdio.h> #include <stdlib.h> in ...
- 2008秋季-计算机软件基础-未交实验报告名单
实验四 序号:108 实验五 序号:108,225,226 351 实验二 353 实验一 356 实验二 360 实验三 365 实验三 367 实验三 368 实验二 372 实验五 转载于:ht ...
- 2008秋季-计算机软件基础-0917课堂用例(2)
循环队列 参见:http://www.cnblogs.com/emanlee/archive/2007/09/17/895463.html #include<stdlib.h> //定义队 ...
最新文章
- React是如何在后台运行的
- 服务管理--systemctl命令
- .NET分层登陆——机房收费系统再总结
- git bash here创建项目无法选择m_git 版本控制初学者指南
- 判断链表是否有环,并找出入环点☆
- 在QEMU硬件环境中启动 kernel 2.6 + busybox as rootfs
- android获取当前显示的view,Android中ViewPager获取当前显示的Fragment
- 调查问卷或量表的选项方向或顺序该如何设置??
- 达梦数据库、表字段创建索引或删除索引,增加表字段、修改字段类型或长度、修改注释sql语句
- 微信开放平台接入支付后不显示头像
- 杭州毕业生就业创业补贴全攻略
- 解决玩Minecraft时鼠标Dpi不稳定问题
- 备案域名绑定服务器后 提示需要备案_网站空间配置和域名解析怎么选择
- 下载追踪:如何监测APP的来源渠道数据
- tps5430应用电路详解_电源转换芯片TPS5430及其应用
- ubantu 16.4升级到 18.04
- C/C++ 折半查找与顺序查找【对比分析】
- WiFi中AP和STA建立连接(Association)的过程
- MVC+EF+LayUI框架的应用-徐新帅-专题视频课程
- 使用多种格式转换方法将MKV转成GIF