当前位置: 首页 > news >正文

c语言程序主体,C语言函数已有主体

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

/*插入数据*/

bool InsertByID()

{//在顺序表L中第i个位置插入新的元素e,i值的合法范围三1<=i<=L.length+1

int i;

ElemType e;

cout<

ShowAllDate();

cout<

cin>>i;

if((i<1)||(i>L.length+1)){cout<

if(L.length==MAXSIZE) {cout<

cout<

cout<

cin>>e.name;

cout<

cin>>e.no;

cout<

cin>>e.sub;

cout<

cin>>e.price;

for(int j=L.length;j>=i;j--){

L.elem[j+1]=L.elem[j];

}

L.elem[i]=e;

++L.length;//更新记录数

cout<

return true;

}

bool DeleteByID()

{//在顺序表L中删除第i个元素,i值的合法范围三1<=i<=L.length

int i;

cout<

cout<

cin>>i;

if((i<1)||(i>L.length)){

cout<

return false;

}

for(int j=i;j<=L.length-1;j++){

L.elem[j]=L.elem[j+1];

}

--L.length;

cout<

return true;

}

/*利用直接插入排序或者折半插入排序按照姓名进行排序;*/

int flag=0;//2表示数据已经更新为姓名排序方案void InsertSort(ElemType *a);

void BInsertSort(ElemType *a);

//姓名排序操作函数

void SelectSort()

{

if(L.length<1){

cout<

return ;

}

cout<

cout<

int n;

cin>>n;

cout<

cout<

cin>>flag;

if(flag!=2){//按姓名排序方式直接显示记录

ElemType a[MAXSIZE];//排序专用临时数组

//把数据拷贝至排序数组中

for(int i=1;i<=L.length;i++) a[i]=L.elem[i];

if(n==2)

BInsertSort(a);

else

InsertSort(a);

//因为默认选择序号1,用户只能操作一次选择,选择错误即默认选择序号1

cout<

cout<

cout<

for(i=1;i<=L.length;i++)

{

cout<

}

cout<

cout<

flag=1;//防止用户输入非1非2数值

}else{//按姓名排序方式改变记录排序方案并显示记录

if(n==2)

BInsertSort(L.elem);

else

InsertSort(L.elem);

//因为默认选择序号1,用户只能操作一次选择,选择错误即默认选择序号1

cout<

cout<

cout<

for(int i=1;i<=L.length;i++)

{

cout<

}

cout<

cout<

}

}

//此处为直接插入排序。对姓名排序

void InsertSort(ElemType a[])

{

for(int i=2;i<=L.length;i++)

if(strcmp(a[i].name,a[i-1].name)<0)

{

a[0]=a[i];

a[i]=a[i-1];

int j;

for(j=i-2;strcmp(a[0].name,a[j].name)<0;j--)

a[j+1]=a[j];

a[j+1]=a[0];

}

}

//此处为折半插入排序。对姓名排序

void BInsertSort(ElemType a[])

{

for(int i=2;i<=L.length;i++)

{

a[0]=a[i];

int low=1,high=i-1;

while(low<=high)

{

int m=(low+high)/2;

if(strcmp(a[0].name,a[m].name)<0) high=m-1;

else low=m+1;

}

for(int j=i-1;j>=high+1;--j) a[j+1]=a[j];

a[high+1]=a[0];

}

}

/*利用快速排序按照成绩进行排序*/

int Partition(ElemType a[],int low,int high)

{//对顺序表a中low..high进行一趟排序,返回枢轴位置

a[0]=a[low];

int pivotkey=a[low].price;

while(low

{

while(low=pivotkey) --high;

a[low]=a[high];

while(low

a[high]=a[low];

}

a[low]=a[0];

return low;

}

//快速排序,对成绩进行排序

void QSort(ElemType a[],int low,int high)

{//调用前置初值:low=1;high=L.length;

//对顺序表a中子序列low..high做快速排序

if(low

int pivotloc=Partition(a,low,high);

QSort(a,low,pivotloc-1);

QSort(a,pivotloc+1,high);

}

}

//成绩排序操作函数

void QuickSort()

{

if(L.length<1){

cout<

return ;

}

cout<

cout<

cin>>flag;

//把数据拷贝至排序数组中

if(flag!=2){//不改变原数据情况下排序并输出结果

ElemType a[MAXSIZE];//排序专用临时数组

for(int i=1;i<=L.length;i++) a[i]=L.elem[i];

//因为默认选择序号1,用户只能操作一次选择,选择错误即默认选择序号1

QSort(a,1,L.length);

cout<

cout<

cout<

for(i=1;i<=L.length;i++)

{

cout<

}

cout<

cout<

flag=1;

}else{

QSort(L.elem,1,L.length);

cout<

cout<

cout<

for(int i=1;i<=L.length;i++)

{

cout<

}

cout<

cout<

flag=3;//在程序内部,2是代表姓名排序后的数据,3代表学号排序结果

}

}

http://www.xdnf.cn/news/850591.html

相关文章:

  • 110道Python面试题(真题),建议收藏!
  • 使用 JavaScript 删除disabled属性
  • 12个国外稳定无限量免费网盘
  • 博客与论坛推广用到的46个地址资源
  • 0day资料收集
  • 黑客网络技术入门教程(非常详细)从零基础入门到精通,看完这一篇就够了
  • Nero 软件各种组件简单介绍
  • 空当接龙求解:java版广度优先
  • VB 数据库交互(一)——交互知识总结
  • 我是如何在SQLServer中处理每天四亿三千万记录的
  • 使用Hbuilder把网站打包成安卓/苹果app(将网址直接打包成app(Hbuilder))
  • 诺顿企业版密码遗失解决办法
  • go语言使用monkey库,进行mock
  • Mysql - date、datetime、timestamp 的区别
  • 浴血凤凰DNF自动辅助开发教程
  • 经典怀旧软件----PP点点通
  • 页面运行时“无法显示XML页”的解决办法
  • drupal7中常见的一个功能模块
  • 百度UIE:Unified Structure Generation for Universal Information Extraction paper详细解读和相关资料
  • apue读书笔记【一】:处理可变参数(1) va_list 、va_arg、 va_start、 va_end
  • 使用smartupload.jar实现文件上传下载
  • Windows Blue十一大新功能汇总 改良Win8
  • mysql转换double_MySQL 字符串 转 int/double CAST与CONVERT 函数的用法
  • 编程语言和翻译工具
  • 怎样修复安装linux系统,linux系统安装图解教程及卸载修复
  • 数据库常用查询
  • unity脚本中的camera相关代码
  • OCX控件数字签名图文教程(个人总结)
  • 腾讯云轻量应用服务器如何搭建自己的CS GO游戏服务器?
  • WiMAX技术到底是什么? 究竟何谓WiMAX?