TRAVERSAL OF LINKED LIST

THIS PROGRAM IS TESTED IN DEV C++ 

#include<stdio.h>
#include<malloc.h>
#include<conio.h>
struct s
{
    int info;
    struct s* link;
};
struct s* start,*ptr;
int main()
{
    char ch;
    start=(struct s*)malloc(sizeof(struct s));
    ptr=start;
    while(1)
    {
        printf("enter number\n");
        scanf("%d",&ptr->info);
        printf("want to enter more y/n \n");
        ch=getch();
        if(ch=='y')
        {
            ptr->link=(struct s*)malloc(sizeof(struct s));
            ptr=ptr->link;
        }
        else
        {
            ptr->link=NULL;
            break;
        }
    }
    ptr=start;
    while(ptr!=NULL)
    {
        printf("%d\t ",ptr->info);
        ptr=ptr->link;
       
    }
}

Previous
Next Post »

ConversionConversion EmoticonEmoticon

:)
:(
=(
^_^
:D
=D
=)D
|o|
@@,
;)
:-bd
:-d
:p
:ng