首先,让我们回顾一下顺序表的优缺点:
2、缺点:
插入、删除效率低;
必须按事先估计的最大元素个数分配连续的存储空间,难以临时扩大。
采用链式存储结构的线性表称为链表。
链表有单链表、循环链表和双向链表等多种类型。
合起来称为结点。
结点包括两类域:
存储数据元素信息的域称为数据域;
每个结点只包含一个指针域的链表,称为单链表。
最后一个结点的指针域为NULL,在图中记为^。
first是头指针,指向链表中的第一个结点,链表中的第一个结点称为头结点
头文件及函数声明等:
#include<stdio.h> //提供system()
#include<stdlib.h> //提供malloc()和free()
#include <malloc.h> //开辟空间
#include <string.h> //提供strcpy()等
typedef int ElemType;
typedef struct node;
typedef int Startus;//获得元素的操作
//结点结构体
typedef struct node
{
ElemType element ; //结点的数据域
struct node *link; //结点的指针域(指向节点的指针)
}Node;
//头结点结构体
typedef struct singleList
{
struct node * first;//头结点
int n;
}SingleList;
SingleList slist;//结构体变量
void menu( );
void init(SingleList *L);
void add(SingleList *L);
void display(SingleList *L);
void del(SingleList * L,int i);
Node * find(SingleList * L,int i);
void insert(SingleList *L,int i);
int change(SingleList *L,int x,int y);
void bubbleSort(SingleList *L);
void save(SingleList *L);
菜单函数:
//定义系统菜单√
void menu( )
{
int op,i,x,y;
printf("===
因篇幅问题不能全部显示,请点此查看更多更全内容