文档介绍:数据结构实验报告
题目:顺序表的基本操作
姓名: 刘运凯
学号: 10070050
班级: 10计科2
正文均采用宋体小四,
一、实验题目及目的(黑体,四号)
顺序表的基本操作
(1)掌握顺序表的数据结构
(2)掌握顺序表的各种基本操作
(3)掌握顺序表的实现
二、实验设计(黑体,四号)
// : Defines the entry point for the console application.
//
#include<iostream>
using namespace std;
#define MaxSize 100
typedef int Elemtype;
typedef struct SqList {
Elemtype data[MaxSize];
int length;
}SqList;
SqList * Init() {
SqList * L;
L = (SqList *)malloc(sizeof(SqList));
if(!L) {
cout<<"error!!"<<endl;
exit(1);
}
L->length = 0;
return L;
}
SqList * Insert_SqList(SqList *L, int i,int x) {
if(L->length == MaxSize) {
cout<<"元素以满!!插入失败!!"<<endl;
exit(-1);
}
if(i < 0 || i > L->length) {
cout<<"插入不合理,插入失败!!"<<endl;
exit(-1);
}
if(L->length >0) {
int n = L->length;
for(int j=0; j<L->length-i; j++) {
L->data[L->length - j] = L->data[L->length - j - 1];
}
L->data[i] = x;
} else
L->data[0] = x;
L->length++;
return L;
}
void print(SqList *L) {
int i;
for(i=0; i< L->length; i++) {
cout<<L->data[i]<< " ";
}
}
void main() {
int i, x, n;
SqList *L;
while(true) {
cout<<" 菜单"<<endl;
cout<<""<<endl;