实验课程名:数据结构
专业班级: 11级计科专升本 学号: 姓名:
实验时间: 4.16 实验地点: K4-207 指导教师:
实验目的:
1、掌握实验用Visual C++6.0上机调试单链表的基本方法;
2、掌握单链表的插入、删除、查找、求表长以及有序单链表的合并算法的实现;
3、进一步掌握循环单链表的插入、删除、查找算法的实现。
试验内容:
代码如下:
#include "stdafx.h"
#include<iostream.h>
#include<stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <iostream.h>
#include <conio.h>
#include <string.h>
#define LISTINCREMENT 10
#define LIST_INIT_SIZE 10
#define ERROR 0
#define OK 1
typedef int ElemType;
/* 链式存储类型 */
typedef struct LNode
{ ElemType data;
struct LNode *next;
}LNode,*LinkList;
//链表插入
int ListInsert(LinkList &L,int i,int e) //ListInsert_L() sub-function
{ LNode *p=L;
int j=0;
while(p&&j<i-1) //find the location
{ p=p->next;
++j;
}
if(!p||j>i-1) //out of location
{ cout<<"Errer! The location is illegal!"<<endl;
return (ERROR);
}
LNode *s;
s=(LinkList)malloc(sizeof(LNode)); //create new LNode
s->data=e;
s->next=p->next;
p->next=s;

本文是关于数据结构实验的报告,重点介绍了如何使用C++实现单链表的插入、删除、查找、求表长以及有序单链表的合并。此外,还涉及了循环单链表的插入、删除、查找算法,并提供了代码实现,包括单链表的合并、排序、逆置等操作。实验旨在提升对链表操作的理解和应用能力。
最低0.47元/天 解锁文章
746

被折叠的 条评论
为什么被折叠?



