线性表
栈&队列
串
二叉树
持续更新中,尽请期待!!!
#include<bits/stdc++.h>
using namespace std;
#define ElemType int
#define Status int
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
Status GetElem_L(LinkList L,int i,ElemType &e){
LinkList p = L->next;
int j = 1;
while(p&&j<i){
p = p->next;
j++;
}
if(!p||j<i)
return 0;
e = p->data;
return 1;
}
Status ListInsert_L(LinkList &L,int i,ElemType e){
LinkList p = L;
int j = 0;
while (p && j < i - 1)
{
p = p->next;
j++;
}
if (!p || j > i - 1)
return 0;
LinkList s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return 1;
}
Status ListDelete_L(LinkList &L,int i,ElemType &e){
LinkList p = L;
int j = 0;
while (p->next && j < i - 1)
{
p = p->next;
j++;
}
if (!(p->next) || j > i - 1)
return 0;
LinkList q = p->next;
p->next = q->next;
e = q->data;
free(q);
return 1;
}
void CreateList_L(LinkList &L,int n){
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
ElemType e;
for (int i = n; i > 0;i--){
LinkList p = (LinkList)malloc(sizeof(LNode));
scanf("%d", &e);
p->data = e;
p->next = L->next;
L->next = p;
}
}
void MergeList_L(LinkList &La, LinkList &Lb, LinkList &Lc){
LinkList pa = La->next;
LinkList pb = Lb->next;
LinkList pc;
La = pc = La;
while (pa && pb)
{
if (pa->data <= pb->data)
{
pc->next = pa;
pc = pa;
pa = pa->next;
}
else
{
pc->next = pb;
pc = pb;
pb = pb->next;
}
}
pc->next = pa ? pa : pb;
free(Lb);
La = NULL;
Lb = NULL;
}