顺序表(未完)
#include<iostream>
using namespace std;
#define MaxSize 50
#define ElemType int
#define InitSize 10
typedef struct {
ElemType data[MaxSize];
int length;
}sqList;
typedef struct {
ElemType* data;
int MaxSize2, length;
}seqList;
void InitList(sqList& L) {
memset(L.data, 0, sizeof(ElemType) * MaxSize);
L.length = 0;
}
void InitseqList(seqList& L) {
L.data = new ElemType[MaxSize];
L.length = 0;
}
bool Empty(sqList L) {
return (L.length>0)?true:false;
}
bool ListInsert(sqList& L, int i, ElemType e) {
if (i<1 || i>L.length + 1)
return false;
if (L.length >= MaxSize)
return false;
for (int j = L.length; j >= i; j--)
L.data[j] = L.data[j - 1];
L.data[i - 1] = e;
L.length++;
return true;
}
bool ListDelete(sqList& L, int i, ElemType& e) {
if (i<1 || i>L.length)
return false;
e = L.data[i - 1];
for (int j = i; j < L.length; j++)
L.data[j] = L.data[j + 1];
L.length--;
return true;
}
int LocateElem(sqList L, ElemType e) {
int i;
for (i = 0; i < L.length; i++) {
if (L.data[i] == e)
return i + 1;
}
return 0;
}
void PrintList(sqList L) {
if (L.length ==0) {
cout << "空表" << endl;
return;
}
for (int i = 0; i < L.length; i++)
cout << L.data[i]<<' ';
}
int main()
{
sqList L;
InitList(L);
PrintList(L);
ListInsert(L,1,1);
PrintList(L);
int e=ListDelete(L, 1, e);
cout << e << endl;
PrintList(L);
}
单链表(待补充)
#include<iostream>
using namespace std;
#define ElemType int
typedef struct LNode {
ElemType data;
struct LNode* next;
}LNode,LinkList;
二叉树(待补充)
#include<iostream>
using namespace std;
#define ElemType int
typedef struct BitNode {
ElemType data;
struct BitNode* lchild, * rchild;
}BitNode, * BitTree;
void PreOrder(BitTree T) {
if (T != NULL) {
PreOrder(T->lchild);
PreOrder(T->rchild);
}
}
void InOrder(BitTree T) {
if (T != NULL) {
InOrder(T->lchild);
InOrder(T->rchild);
}
}
void PostOrder(BitTree T) {
if (T != NULL) {
PostOrder(T->lchild);
PostOrder(T->rchild);
}
}
|