搜索
首页 电脑/网络 程序设计 C/C++

试用C语言编程

1.构造一个空线性表,算法见附件.2.在线性表中插入元素,算法见附件.3.销毁此线性表.

全部回答

2008-03-21

0 0
    //顺序表的储存结构及相关运算// ypedefstruct{chardata[32];intlength;}SqList;voidCreateList(SqList*&L,chara[],intn)//建立{inti;for(i=0;idata[i]=a[i];L->length=n;}voidInitList(SqList*&L)//初始化{L=newSqList;L->length=0;}voidDestroyList(SqList*&L)//摧毁{delete(L);}intListEmpty(SqList*L)//测空{return(L->length==0);}intListLength(SqList*L)//求长{return(L->length);}voidDispList(SqList*L)//输出{inti;if(ListEmpty(L))return;for(i=0;ilength;i++)coutdata[i]L->length)return0;e=L->data[i-1];return1;}intLocateElem(SqList*L,chare)//查找e{inti;for(i=0;ilength&&L->data[i]!=e;i++){}if(i>=L->length)return0;elsereturni+1;}intListInsert(SqList*&L,inti,chare)//插入{intj;if(iL->length+1)return0;i--;for(j=L->length;j>i;j--)L->data[j]=L->data[j-1];L->data[i]=e;L->length++;return1;}intListDelete(SqList*&L,inti,char&e)//删除数据{intj;if(iL->length)return0;i--;e=L->data[i];for(j=i;jlength-1;j++)L->data[j]=L->data[j+1];L->length--;return1;}//stdafx。
    h:includefileforstandardsystemincludefiles,//orprojectspecificincludefilesthatareusedfrequently,but//arechangedinfrequently//#pragmaonce#defineWIN32_LEAN_AND_MEAN//Excluderarely-usedstufffromWindowsheaders#include#include#include#includeusingnamespacestd;// :Definestheentrypointfortheconsoleapplication。
    //题目太长了--b……,总之大概这么用吧。#include"stdafx。h"#include"SqList。h"int_tmain(intargc,_TCHAR*argv[]){SqList*L;chare;InitList(L);ListInsert(L,1,'a');ListInsert(L,2,'b');ListInsert(L,3,'c');ListInsert(L,4,'d');ListInsert(L,5,'e');DispList(L);cout<<endl;cout<<"ThisListhas"<<ListLength(L)<<"long。
    "<<endl;cout<<"是否为空的状态"<<ListEmpty(L)<<endl;GetElem(L,3,e);cout<<"输出第三个元素"<<e<<endl;cout<<"元素a的位置"<<LocateElem(L,'a')<<endl;ListInsert(L,4,'f');DispList(L);cout<<endl;cout<<"===========================插入过f================================"<<endl;ListDelete(L,3,e);cout<<"被删除的元素是"<<e<<endl;cout<<endl;DispList(L);cout<<endl;cout<<"===========================删除了第3元素================================"<<endl;DestroyList(L);getchar();return0;}/*我以前写的,有点多,不过含有建立,插入,销毁动作。
    顺序表的*/。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
C/C++
硬件
电脑装机
程序设计
互联网
操作系统/系统故障
笔记本电脑
反病毒
百度
软件
程序设计
C/C++
VB
数据库
汇编语言
JAVA相关
VC++
C#/.NET
其他编程语言
C/C++
C/C++
举报
举报原因(必选):
取消确定举报