randomposts
Powered by Blogger.

Single Link List Last Code in C Programming Turbo C

No comments



/*Single Link List Last Code in C Programming Turbo C*/

#include<stdio.h>
#include<conio.h>


struct linklist
{
            int no;
            struct linklist *next;
};

            typedef struct linklist node;
void main()
{

            void display(node*);
            void create(node*);
            void insertlast(node *);
             node*head;
             clrscr();

                        head=(node*)malloc(sizeof(node));
                        create(head);
                        insertlast(head);
                        display(head);
                        getch();
}





            void create(node*  list)
            {
                        printf("Enter no,-1 for end");
                        scanf("%d",&list-> no);

                                    if(list-> no==-1)
                                    list-> next=NULL;
                        else
                        {
                                    list->next=(node*) malloc(sizeof(node));
                                    create (list-> next);
                        }

            }

            void display(node * list)
            {
                        while(list-> next!=NULL)
                        {
                                    printf("%d",list->no);
                                    list=list-> next;
                        }
            }


void insertlast(node *list)
{
            node *new1;
            new1=(node *)malloc(sizeof(node));
            while(list->next!=NULL)
            {
                        list=list->next;
            }
            list->next=new1;
            new1->next=NULL;
            printf("Enter no");
      //    list->no=100;
       scanf("%d",&list->no);
}

No comments :

Post a Comment