Singly Linked List of N Students Data using queues

Singly linked list of n student data like id, name, branch using queues and 3rd Sem Data structure and Application lab 5b program

Create a SLL queue of N Students Data.

/* Create a SLL queue of N Students Data */

#include <stdio.h>
#include <stdlib.h>
#include<malloc.h>
#include<string.h>
void display();
void queue();
void insertrear();
void create();
struct student{
int idno;
char name[20],branch[20];
struct student *next;
};
struct student *first=NULL,*last=NULL,*temp;
int main(){
    queue();
}
void queue(){
    int ch,n,i;
    while(1){
        printf("1.create\n 2.display\n 3.exit\n");
        printf("Enter your choice:");
        scanf("%d",&ch);
        switch(ch){
            case 1:printf("\n Enter the number of student\n");
                    scanf("%d",&n);
                    for(i=0;i<n;i++)
                        insertrear();
                    break;
            case 2:display();
                    break;
            case 3:exit(0);
            break;
            default:printf("Invalid choice\n");
        }
    }
}
void create(){

    int data;
    char name[20],branch[20];
    temp=(struct student *)malloc(sizeof(struct student));
    temp->next=NULL;
    printf("\n Enter the ID no,Name,Branch\n ");
    scanf("%d%s%s",&data,name,branch);
    temp->idno=data;
    strcpy(temp->name,name);
    strcpy(temp->branch,branch);
}
void insertrear(){
    if(first==NULL){
        create();
        temp->next=NULL;
        first=temp;
    }else{
        create();
        last=first;
        while(last->next!=NULL){
            last=last->next;
        }last->next=temp;
    }
}
void display(){
    struct student *p;
    if(first==NULL){
        printf("\n List is Empty");
        return;
    }
    p=first;
    printf("\n Contents of list\n ");
    while(p!=NULL){
        printf("\n ID no=%d\n Name=%s\n Branch=%s\n",p->idno,p->name,p->branch);
        p=p->next;
    }

}

Leave a Reply

Your email address will not be published. Required fields are marked *