如何修改代码实现功能?
#include "stdafx.h"#include "stdio.h"
#include "stdlib.h"
#define OK 1
#define NULL 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct node
{
int data;
struct node *next;
}Linklist;
Status Initilist()
{
Linklist *head;
if(head=(Linklist *)malloc(sizeof(node)==NULL))
{
return 0;
}
head->next=NULL;
return OK;
}
Linklist * createlist(int n)
{
int k;
Linklist *head,*r,*p;
p=(Linklist *)malloc(sizeof(Linklist));
p->next=NULL;
head=p;
for(k=1;k<=n;k++)
{
r=(Linklist *)malloc(sizeof(Linklist));
printf("input value:\n");
scanf("%d",&(r->data));
r->next=NULL;
p->next=r;
p=r;
}
return (head);
}
void Printlist(Linklist *head)
{
Linklist *p;
p=head->next;
while(p!=NULL)
{
printf("%4d",p->data);
p=p->next;
}
printf("\n");
}
Linklist *find(Linklist *head,int i)
{
int j;
Linklist *p;
p=head->next;
j=1;
while(p!=NULL&&j<i)
{
p=p->next;
j++;
}
printf("\n");
return p;
}
void insert(Linklist *head,int i,int k)
{
Linklist *p;
Linklist *s;
int j=0;
p=head;
while(p&&j<i-1)
{
p=p->next;
++j;
}
s=(Linklist *)malloc(sizeof(Linklist));
s->data=k;
s->next=p->next;
p->next=s;
}
Linklist * nishunxu(int n)//如何将链表元素逆序输出?例如我输入是1,2,3,4,5,插入6到第六个节点,逆序输出6,5,4,3,2,1?
{
Linklist *p;
Linklist *head;
int k=0;
head->next=NULL;
for(k=n+1;k>=1;k--)//用for循环怎么做?
{
p->next=head->next;
head->next=p;
}
return p;
}
int main(int argc, char* argv[])
{
Linklist *L;
Linklist *q;
Linklist *head;
int x;
int k;
int select;
int i=0;
Initilist();
L=createlist(5);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
printf("input k:\n");
scanf("%d",&k);
insert(L,i,k);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
q=find(L,i);
printf("%d",*q);
L=nishunxu(5);
Printlist(L);
return 0;
}