链表的基本操作
- 创建(头插法 / 尾插法)
- 遍历
- 查找(按值 / 按位置)
- 插入
- 删除
单链表:
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef struct LNode{
int data;
struct LNode *next;
}LNode;
int n; //链表长度
// 创建:头插法(逆序)
void create_head(LNode *&L, int n){
// 头结点
L = (LNode *)malloc(sizeof(LNode));
L->next = NULL;
// 开始
LNode *s;
for(int i=0; i<n; i++){
s = (LNode *)malloc(sizeof(LNode));
int e;
scanf("%d", &e);
s->data = e;
//
s->next = L->next;
L->next = s;
}
}
// 创建:尾插法(顺序)
void create_tail(LNode *&L, int n){