头文件
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define INIT_SIZE 100
#define INCREMENT 10
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef int Status;
typedef int ElemType;
#pragma warning(disable:4996)
#include "DataStructure.h"
typedef struct LNode {
ElemType data;
struct LNode *next;
}LNode, *LinkList;
Status GetElem_L(LinkList p, int i, ElemType& x) {
if (i < 0)
{
return ERROR;
}
LNode *L = p->next;
while (i > 0 && L != NULL)
{
L = L->next;
i--;
}
if (i == 0)
{
x = L->data;
return OK;
}
return ERROR;
}
Status ListInsert_L(LinkList& L, int i, ElemType x) {
LinkList p = L;
L = L->next;
while (L&&i>1)
{
L = L->next;
i--;
}
if (i==1)
{
LNode* node = (LinkList)malloc(sizeof(LNode));
node->data = x;
node->next = L->next;
L->next = node;
L = p;
return OK;
}
return ERROR;
}
Status CreatList_H(LinkList& p, int n) {
LinkList L = p;
int temp = 0;
if (!L)
{
return OVERFLOW;
}
L->next = NULL;
while (n--)
{
L->next = (LinkList)malloc(sizeof(LNode));
L = L->next;
if (!L)
{
return OVERFLOW;
}
L->data = n;
printf("\n链表输入:%d", L->data);
}
L->next = NULL;
}
Status PrintfLinkList(LinkList L) {
L = L->next;
printf("\n链表输出:");
while (L)
{
printf("%d\t", L->data);
L = L->next;
}
return OK;
}
Status InitLinkList(LinkList& L) {
L = (LinkList)malloc(sizeof(LinkList));
return OK;
}
Status DeleteLinkList(LinkList& L, int i, ElemType& x) {
}
int main() {
LinkList L;
InitLinkList(L);
CreatList_H(L, 10);
ListInsert_L(L, 3, 10);
PrintfLinkList(L);
}