- 250
- 0
- 约3.89千字
- 约 3页
- 2017-05-18 发布于重庆
- 举报
顺序表的操作实验报告馒头制作
实验二 顺序表的操作实验报告
班 级 10计科2 学号 20104012010 姓名 翁朝伟 实验名称 顺序表的操作 实验目的 掌握线性表的顺序存储结构的基本概念、基本操作和应用 实验环境 硬件环境:微型计算机 软件环境:Windows 2000或以上版本,turboc2.0 实验内容 1.创建顺序表,顺序表的元素的值由用户从键盘输入。
2.在已经创建的顺序表中插入一个元素。从键盘读入元素值和插入位置,在指定的位置前插入。
3.在已经创建的顺序表中删除一个元素。从键盘读入欲删除的元素位置,在指定的位置删除元素。 实验步骤及结果 线性表的插入 线性表的删除
#include stdio.h
#define OK 1
#define ERROR 0
#define ElemType int
#define LIST_INT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList *L){
L-elem=(ElemType *)malloc(LIST_INT_SIZE*sizeof(ElemType));
if (!L-elem) return OK;
L-length=0;
L-listsize=LIST_INT_SIZE;
return OK;}
int ListInsert_Sq(SqList *L,int i,ElemType e) {
ElemType *p, *q, *newbase;
if (i 1 || i L-length+1) return ERROR;
if (L-length = L-listsize){
newbase = (ElemType *)realloc(L-elem, (L-listsize+LISTINCREMENT)*sizeof (ElemType));
if (!newbase) return ERROR;
L-elem = newbase;
L-listsize += LISTINCREMENT; }
q = (L-elem[i-1]);
for (p = (L-elem[L-length-1]); p=q; --p) *(p+1) = *p;
*q = e;
++L-length;
return OK;}
int main(){
SqList *L;
int i,e;
if (! InitList_Sq(L)) return ERROR;
printf(Please input the length of the list(1-100) : );
scanf(%d, L-length);
for(i=0;i L-length;i++)
scanf(%d, L- elem[i]);
printf(The old Sqlist is : \n);
for(i=0;i L-length;i++)
printf(%d ,L- elem[i]);
printf(\nPlease input the location to insert (1 to L-length+1) : \n);
scanf(%d,i);
while(i1||i L-length+1)
{
printf(Please input the location to insert (1 to 11) : \n );
scanf(%d,i);}
printf(Please input the integer to insert (eg,58) : );
scanf(%d,e);
if(ListInsert_Sq(L,i,e)){
printf(The new Sqlist is : );
for(i=0;i L-length;i++)
printf(%d ,L- elem[i]);}} #include stdio.h
#define OK 1
#define ERROR 0
#define ElemType int
#define LIST_INT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList *L){
L-
原创力文档

文档评论(0)