分类：电脑/网络-程序设计-C/C++
问题：试用C语言编程1.构造一个空线性表,算法见附件.2.在线性表中插 
1.构造一个空线性表,见附件.2.在线性表中插入元素,算法见附件.3.销毁此线性表.
回答：//顺序表的储存结构及相关运算// ydefstruct{chardata[32];intlength;}SqList;voidCreateList(SqList*&L,chara[],intn)//建立{inti;for(i=0;i<n;i++)L->data[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;i<L->length;i++)cout<<L->data[i]<<"";}intGetElem(SqList*L,inti,char&e)//求第i个元素值{if(i<1||i>L->length)return0;e=L->data[i-1];return1;}intLocateElem(SqList*L,chare)//查找e{inti;for(i=0;i<L->length&&L->data[i]!=e;i++){}if(i>=L->length)return0;elsereturni+1;}intListInsert(SqList*&L,inti,chare)//插入{intj;if(i<1||i>L->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(i<1||i>L->length)return0;i--;e=L->data[i];for(j=i;j<L->length-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<stdio.h>#include<tchar.h>#include<conio.h>#include<iostream>usingnamespacestd;// :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;}/*我以前写的,有点多,不过含有建立,插入,销毁动作。顺序表的*/