#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "stdlib.h"
#include"iostream"
#include"typeinfo"
#include "math.h"
#include "time.h"
using namespace std;
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define MAXSIZE 20
typedef int Status;
typedef int ElemType;
typedef struct node {
ElemType shu;
struct node* next;
}Node;
typedef struct node* linklist;
Status insert(linklist l, int index, ElemType e)
{
linklist p,s;
p = l;
int j = 1;
while (j < index && p)
{
p = p->next;
++j;
}
if (j > index || !p)
{
cout << "失败了哦"<shu = e;
s->next = p->next;
p->next = s;
cout << "添加成功了哦" << endl;
return OK;
}
Status initlist(linklist l)
{
linklist p;
l->next = NULL;
for (int i = 10; i > 0; i--)
{
p = (linklist)malloc(sizeof(Node));
p->shu = i;
p->next = l->next;
l->next = p;
}
cout << "win";
return OK;
}
Status del(linklist l, int index)
{
linklist p,s;
int j = 1;
p = l;
while (j < index&&p->next)
{
p = p->next;
++j;
}
if (j > index || !p->next)
{
cout << "删除失败了哦" << endl;
return FALSE;
}
s=p->next;
p->next = s -> next;
free(s);
cout << "删除成功" << endl;
return OK;
}
Status clearlist(linklist l)
{
linklist p = l->next,s;
while (p->next)
{
s= p->next;
free(p);
p = s;
}
return OK;
}
Status search(linklist l, int index)
{
int j = 0;
while (j < index&& l)
{
l = l->next;
++j;
}
if (j > index || !l)
{
cout << "找不到哦"<shu<next;
cout << s->shu <<" ";
}
// *ll = &l;
insert(&l, 10, 99);
s = &l;
s = s->next;
while (s)
{
cout << s->shu << " ";
s = s->next;
}
del(&l, 2);
s = &l;
s = s->next;
while (s)
{
cout << s->shu << " ";
s = s->next;
}
search(&l, 9);
//clearlist(&l);
}