FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
3.8k views
in VTU B.Tech (CSE-III Sem) Data Structure Lab by Goeduhub's Expert (7.6k points)
single linked list program

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Single Linked list Program

Program

#include<string.h>

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

struct stud

{

    char usn[11],name[15],branch[4],phno[11];

    int sem;

    struct stud *next;

}*f=NULL,*r=NULL,*t=NULL;

void ins(int ch)

{

    t=(struct stud*)malloc(sizeof(struct stud));

    printf("\nEnter USN:");

    scanf("%s",t->usn);

    printf("Enter Name:");

    scanf("%s",t->name);

    printf("Enter Branch:");

    scanf("%s",t->branch);

    printf("Enter Sem:");

    scanf("%d",&t->sem);

    printf("Enter Phno:");

    scanf("%s",t->phno);

    t->next=NULL;

    if(!r)

        f=r=t;

    else

    {

        if(ch)

        {

            r->next=t;

            r=t;

        }

        else

        {

            t->next=f;

            f=t;

        }

    }

}

void del(int ch)

{

    if(!f)

        printf("\nList Empty");

    else

    {

        struct stud *t1;

        if(f==r)

        {

            t1=f;

            f=r=NULL;

        }

        else if(ch)

        {

            t1=r;

            for(t=f;t->next!=r;t=t->next)

                r=t;

            r->next=NULL;

        }

        else

        {

            t1=f;

            f=f->next;

        }

        printf("\nElement deleted is:\n");

        printf("USN:%s\nName:%s\nBranch:%s\nSem:%d\nPhno:%s\n",t1->usn,t1->name,t1->branch,t1->sem,t1->phno);

        free(t1);

    }

}

void disp()

{

    if(!f)

        printf("\nList Empty!!!");

    else

        printf("\nList elements are:\n");

    for(t=f;t;t=t->next)

        printf("\nUSN:%s\nName:%s\nBranch:%s\nSem:%d\nPhno:%s\n",t->usn,t->name,t->branch,t->sem,t->phno);

}

void main()

{

    int ch,n,i;

    printf("\n........Menu..........,\n");

    printf("1.Create\n");

    printf("2.Display\n");

    printf("3.Insert at end\n");

    printf("4.Delete at end\n");

    printf("5.Insert at beg\n");

    printf("6.Delete at beg\n");

    printf("7.Exit\n");

    while(1)

    {

        printf("\nEnter choice:");

        scanf("%d",&ch);

        switch(ch)

        {

            case 1: printf("\nEnter no. of nodes:");

                    scanf("%d",&n);

                    for(i=0;i<n;i++)

                        ins(0);

                    break;

            case 2:disp();break;

            case 3:ins(1);break;

            case 4:del(1);break;

            case 5:ins(0);break;

            case 6:del(0);break;

            case 7:exit(0);

            default:printf("\nInvalid choice!!!!");

        }

    }

}

 Output

output


For more Visvesvaraya Technological University(VTU) CSE-III Sem Data Structure Lab Experiments Click Here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...