- 66
- 0
- 约9.78千字
- 约 19页
- 2017-01-06 发布于贵州
- 举报
c语言实验报告c语言实验报告
计算机软件技术基础实验报告
实验一:线性表的排序与查找
一.实验内容
键盘输入一组无序数据,添加到线性表中;
排序线性表并输出排序结果;
键盘输入一个数,并插入到排好序的线性表中(要求插入后的表仍为有序表),输出结果;
键盘输入一个数,并从线性表中删除相应的数据,输出结果。
二,源程序
// Experiment1.cpp : 定义控制台应用程序的入口点。
//
#include stdafx.h
#include iostream
#include conio.h
// 程序实现有各种方法,这里给出一个实例。
// 定义一个线性表
const int nMaxSize = 15; // 最大值
int nLen = 0; // 表中元素个数
int nLinearList[nMaxSize];
// 定义操作
void LSort();
void LOut();
void LInsert(int n);
void LDelete(int n);
int main(int argc,TCHAR*argv[])
{
// 输入数据并放入线性表中
printf(Please input data\n); // std::cout Please input data\n;
int nIn = 0;
for (int i = 1; i = 10; i++)
{
scanf(%d,nIn); // std::cin nIn;
nLinearList[i] = nIn;
nLen++;
}
LSort(); // 排序线性表
LOut(); // 输出结果
printf(Please input a data to insert \n);
scanf(%d,nIn);
LInsert(nIn); // 输入一个数字,并插入到线性表中
LOut();
printf(Please input a data to delete \n);
scanf(%d,nIn);
LDelete(nIn); // 输入一个数字,并从线性表中删除
LOut();
char chTmp;
printf(Please input a char to finish this program.);
chTmp = getch();
return 0;
}
void LSort() // 冒泡排序,由大到小
{
int j,F,k,M;
F=nLen;
while(F0)
{k=F-1;F=0;
for(j=1;j=k;j++)
{if(nLinearList[j]nLinearList[j+1])
{ M=nLinearList[j];
nLinearList[j]=nLinearList[j+1];
nLinearList[j+1]=M;
F=j; }}}
}
void LOut()
{
printf( \n);
for (int i = 1; i = nLen; i++)
{
printf( %d, , nLinearList[i] );
}
printf( \n);
}
void LInsert(int n)
{
int i,j;i=1;
while (inLen)
{ if(nLinearList[i]=n)
{ nLen++;
for(j=nLen;j=i;j--)
nLinearList[j+1]=nLinearList[j];
nLinearList[i]=n;
break;}
i++;}
}
void LDelete(int n)
{
int i,j;
for(i=1;i=nLen;i++)
{if(nLinearList[i]==n)
{for(j=i;j=(nLen-1);j++)
nLinearList[j]=nLinearList[j+1];
nLen--;
break;}}}
三 运行结果
实验2:栈与队列的应用
实验内容
键盘输入算数表达式,并放入队列当中;
应用栈的概念设计表达式求值算法;
输出表达式求值结果
二.源程序
// Experiment2.cpp : 定义控制台应用程序的入口点。
#include stdio.h
#include String.h
#include stdlib.h
#include math.h
// 程序实现有各种方法,这里给出一个实例。
const int MAX_LEN = 10; // 字符串的长度
const int MAX_SIZE =
您可能关注的文档
- CSAMT测量原理.doc
- CVS使用详解.doc
- CW11T梁预制方案.doc
- cwgl_jy0301.doc
- CT工业厂房投标方案.doc
- cwalfxcwalfx.docx
- CVTE笔试题_答案.doc
- C_C++软件开发规范.doc
- C上机练习题全.doc
- C一期土方招标文件.doc
- 2025-2026学年张家口市宣化县三年级数学第一学期阶段质量跟踪监视试题(含答案).docx
- 2026年日语培训机构运营风险及应对措施报告.docx
- 2026年服务业瑜伽馆课程创新与市场定位分析报告.docx
- 2026年脑机接口医疗应用的商业化运营模式.docx
- 2026年能源大数据行业应用领域分析报告.docx
- 财务管理制度2.docx
- 2025-2026学年张家口市宣化县四年级数学上学期期中质量跟踪监视试题含解析.docx
- 2025-2026学年张家口市宣化县四年级数学第一学期期中质量跟踪监视试题(含答案).docx
- 2026年汽车传感器行业市场竞争格局及市场报告.docx
- 2026年智能制造在机械制造中的应用案例报告.docx
原创力文档

文档评论(0)