上一篇文章主要实现了单链表的基本操作,这篇文章主要讲的是单链表的具体应用
1.单链表的逆序输出(mylist.h)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "mylist.h"
void PrintList(List L)
{
Position P = L;
assert(L != NULL);
if(IsEmpty(L))
{
printf("List empty\n");
}
else
{
do
{
P = Next(P);
printf("%3d", Retrieve(P));
}while(!IsLast(P));
putchar('\n');
}
}
void Print(Position P)
{
if(P == NULL)
return;
else
Print(Next(P));
printf("%3d", Retrieve(P));
}
void ReversedPrint(List L)
{
Position P = First(L);
Print(P);
}
int main(void)
{
Position P;
List L;
int i;
MakeEmpty(&L);
P = L;
for(i = 0; i < 5; ++i)
{
In