文档介绍:本文格式为Word版,下载可任意编辑
— 2 —
数据结构课内实验报告(1)
实 实 验 报 告 ( (2022
/ 2022 学年 第 第 一 学期)
课程名称 数据布局 测验名称 线性表及多项式--) {
L-element[j + 1] = L-element[j];
5
}
L-element[i + 1] = x;
L - n = L-n + 1;
return OK; } Status Delete(SeqList *L, int i){
int j; if(i0||iL-n-1){
return ERROR;
} if(!L-n){
return ERROR;
}
for(j=i+1;jL-n;j++){
L-element[j-1]=L-element[j];
} L-n--;
本文格式为Word版,下载可任意编辑
— 5 —
return OK; } int Output(SeqList L) {
int i;
if (!)
return ERROR;
for (i = 0; i = - 1; i++)
printf(%d , [i]);
return OK; } void Destroy(SeqList *L){
(*L).n=0;
(*L).maxLength=0;
free((*L).element); } void main() {
int i,x;
6
SeqList list;
Init(list, 10);
for (i = 0; i 9; i++) {
Insert(list, i - 1, i);
}
Output(list);
printf(\n); Delete(list,0);
Output(list);
Find(list,2,x);
printf(\nthe value is:);
本文格式为Word版,下载可任意编辑
— 6 —
printf(%d,x);
Destroy(list); }
# # typedef int ElemType; typedef int Status; #define ERROR 0 #define OK 1 typedef struct Node {
ElemType element;
struct Node * link;
}Node; typedef struct {
struct Node* head;
int n; }HeaderList; Status Init(HeaderList *h) {
h-head=(Node*)malloc(sizeof(Node));
if(!h-head){
return ERROR;
7
}
h-head-link = NULL;
h-n = 0;
return OK; } Status Find(HeaderList *h,int i,ElemType *x){
Node *p;
int j;
if(i0||ih-n-1){
本文格式为Word版,下载可任意编辑
— 7 —
return ERROR;
}
p=h-head-link;
for(j=0;ji;j++){
p=p-link;
}
*x=p-element;
return OK; } Status Insert(HeaderList *h, int i, ElemType x) {
Node *p, *q;
int j;
if (i-1 || ih-n - 1)
return ERROR;
p = h-head;
for (j = 0; j = i; j++) {