#include
#include
#include
typedef struct node
{
char data;
struct node *nextPtr;
}*LinkList, Lnode;
static void CreateList(LinkList *headPtr, LinkList *tailPtr);
static void VisitList(LinkList headPtr);
static void DestroyList(LinkList *headPtr, LinkList *tailPtr);
int main(void)
{
LinkList headPtr = NULL, tailPtr = NULL;
CreateList(&headPtr, &tailPtr);
VisitList(headPtr);
DestroyList(&headPtr, &tailPtr);
getch();
return 0;
}
static void CreateList(LinkList *headPtr, LinkList *tailPtr)
{
char ch;
LinkList newPtr;
printf("Enter create list string: ");
fflush(stdin);
while (1)
{
scanf("%c", &ch);
if (ch == '\n')
{
return ;
}
if ((newPtr = (LinkList)malloc(sizeof(Lnode))) == NULL)
{
exit(1);
}
newPtr -> data = ch;
newPtr -> nextPtr = NULL;
if (*headPtr == NULL)
{
newPtr -> nextPtr = *headPtr;
*headPtr = newPtr;
}
else
{
(*tailPtr) -> nextPtr = newPtr;
}
*tailPtr = newPtr;
}
}
static void VisitList(LinkList headPtr)
{
while (headPtr != NULL)
{
printf("%c", headPtr -> data);
headPtr = headPtr -> nextPtr;
}
printf("\n");
}
static void DestroyList(LinkList *headPtr, LinkList *tailPtr)
{
LinkList tempPtr;
while (*headPtr != NULL)
{
tempPtr = *headPtr;
*headPtr = (*headPtr) -> nextPtr;
free(tempPtr);
}
*headPtr = NULL;
*tailPtr = NULL;
}