#include <stdio.h>
#pragma warning(disable:4996)
#include <stdlib.h>
#define InitSize 10
#include <stdbool.h>
typedef struct LNode{
int data;
struct LNode* next;
}LNode,Linklist;
_Bool InitList(Linklist* L)
{
L = (LNode*)malloc(sizeof(LNode));
if (L == NULL)
return 0;
L->next = NULL;
return 1;
}
_Bool ListInsert1(Linklist* L, int i, int e)
{
if (i < 1)
return 0;
Linklist* p;
int j = 0;
p = L;
while (p != NULL && j < i - 1)
{
p = p->next;
j++;
}
if (p == NULL)
return 0;
LNode* s = (LNode*)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return 1;
}
void Printfdan(Linklist* L)
{
Linklist* p;
p = L;
while (p->next != NULL)
{
p = p->next;
printf("%d\n", L->data);
}
}
int main()
{
Linklist L;
Linklist* l = &L;
InitList(l);
ListInsert1(l, 1, 1);
ListInsert1(l, 2, 2);
ListInsert1(l, 3, 3);
Printfdan(l);
}
#pragma warning(disable:4996)
#include <stdlib.h>
#define InitSize 10
#include <stdbool.h>
typedef struct LNode{
int data;
struct LNode* next;
}LNode,Linklist;
_Bool InitList(Linklist* L)
{
L = (LNode*)malloc(sizeof(LNode));
if (L == NULL)
return 0;
L->next = NULL;
return 1;
}
_Bool ListInsert1(Linklist* L, int i, int e)
{
if (i < 1)
return 0;
Linklist* p;
int j = 0;
p = L;
while (p != NULL && j < i - 1)
{
p = p->next;
j++;
}
if (p == NULL)
return 0;
LNode* s = (LNode*)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return 1;
}
void Printfdan(Linklist* L)
{
Linklist* p;
p = L;
while (p->next != NULL)
{
p = p->next;
printf("%d\n", L->data);
}
}
int main()
{
Linklist L;
Linklist* l = &L;
InitList(l);
ListInsert1(l, 1, 1);
ListInsert1(l, 2, 2);
ListInsert1(l, 3, 3);
Printfdan(l);
}