วันจันทร์ที่ 3 มีนาคม พ.ศ. 2551

Single Link List

#include "stdio.h"
#include "conio.h"
#include "string.h"

typedef struct ptr
{
int id;
char name[25];
struct ptr *next;
}Ptr;
Ptr *start , *p , *q , *go;

void main()
{
start = new Ptr;
strcpy(start->name,"Aree");

p = new Ptr;
strcpy(p->name,"Suda");

q = new Ptr;
strcpy(q->name,"Yupin");

start->next = p;
p->next = q;
q->next = NULL;

clrscr();
printf("%s \n",start->name);
printf("%s \n",p->name);
printf("%s \n",q->name);

printf("%s \n",start->next->name);
printf("%s \n\n\n",start->next->next->name);

go = start;
while(go != NULL)
{
printf("%s \n",go->name);
go = go->next;
}
}

ไม่มีความคิดเห็น: