终端没有任何输出也没有输出完成显示
#include <stdbool.h>
struct Node;
typedef struct Node *List;
typedef struct Node *Position;
bool IsEmpty(List L);
bool IsLast(Position P);
char GetKey(Position P);
int GetValue(Position P);
void SetKey(Position P,char);
void SetValue(Position P,int);
void Advance(Position P1,Position P2);
Position Find(char key,List L);
void Delete(char name,List L);
Position FindPrevious(char name,List L);
void Insert(char name,int value,List L,Position P); //将新节点\
插入p之后
void show(List L);
struct Node
{
char key;
int value;
Position next;
};
#include "Linklist.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
bool IsEmpty(List L){
return L->next == NULL;
}
bool IsLast(Position P){
return P->next == NULL;
}
void Advance(Position P1,Position P2){
P1->next=P2;
}
char GetKey(Position P){
return P->key;
}
int GetValue(Position P){
return P->value;
}
void SetKey(Position P,char name){
P->key=name;
}
void SetValue(Position P,int value){
P->value=value;
}
Position Find(char key,List L){
Position P;
P=L->next;
while (P != NULL && P->key!=key)
{
if (!IsLast(P))
P=P->next;
}
if (IsLast(P)) //为什么要加括号?
return NULL;
else
return P;
}
void Delete(char name,List L){
Position P,temp;
P=FindPrevious(name,L);
if (P != NULL)
{
temp=P->next;
P->next=temp->next;
free(temp);
}
else
{
printf("Node doesn't exist!\n");
}
}
Position FindPrevious(char name,List L){
Position P;
P=L;
while (P->next != NULL && P->next->key!=name)
{
P=P->next;
}
if (IsLast(P)) //为什么要加括号?
return NULL;
else
return P;
}
void Insert(char name,int value,List L,Position P){
Position new;
new=malloc(sizeof(struct Node));
if (new==NULL)
printf("Out of space!!!"); //不知道error咋用。。
new->key=name;
new->next=P->next;
P->next=new;
}
void show(List L){
Position P;
printf("%-5s%-5s","key","value");
if (IsEmpty(L))
printf("please set some nodes.\n");
else
P=L->next;
while (!IsLast(P))
{
printf("%-5s%-5d\n",P->key,P->value);
P=P->next;
}
}
int main()
{
struct Node *p0,*p1,*p2;
SetKey(p0,'a');
SetKey(p1,'b');
SetKey(p2,'c');
SetValue(p0,15);
SetValue(p1,29);
SetValue(p0,37);
Advance(p0,p1);
Advance(p1,p2);
Advance(p2,NULL);
show(p0);
return 0;
}