SEP -DATA STRUCTURE

PART-A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

 
  
 
  
5. Write a C Program to implement insert at the beginning of a singly linked list and display

#include< stdio.h>  
#include< conio.h>
#include< stdlib.h>  
struct node   
{  
    int data;  
    struct node *next;   
};  
struct node *start;  
              
void insert_begin();   
   
   
void print();  
void main ()  
{  
    int ch=0;  
    while(ch!=8)   
    {    
        printf("\nEnter the operation to be performed\n");    
        printf("\n1.Insert in the begining \n 2 .Show \n 3.Exit\n");           
        scanf("\n%d",&ch);  
        switch(ch)  
        {        /*function calls of all the operations */
            case 1:  
            insert_begin();       
            break;  
             
            case 2: print();        
            break; 
            
            case 3: exit(0);  
             break; 
             
            default:  
            printf("Enter valid option");  
        }  
    }  
    getch();
}     


void insert_begin()                  //to insert the node at the beginnning of linked list
{  
    struct node *p;  
    int value;  
    p=(struct node *) malloc(sizeof(struct node *));  
    if(p==NULL)  
    {  
        printf("\nOVERFLOW");  
    }  
    else  
    {  
        printf("\nEnter value\n");    
        scanf("%d",&value);    
        p->data=value;  
        p->next=start;  
        start=p;  
    }  
}  
void print()    //to print the values in the linked list
{  
    struct node *p;  
    p=start;   
    if(p==NULL)  
    {  
        printf("Nothing to print");  
    }  
    else  
    {  
        printf("\nprinting values\n");   
        while (p!=NULL)  
        {  
            printf("\n%d",p->data);  
            p=p->next;  
        }  
    }  
}