

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The c++ code for implementing a simple linked list with the ability to enqueue, dequeue, and display elements. The code includes a struct definition for a student with id and name fields, a main function with a while loop for user input, and switch statements for each function. The user can interact with the list by pressing keys corresponding to the desired function. This document could be useful for students studying data structures and algorithms, particularly linked lists, in a computer science or engineering program.
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include <iostream.h> #include <conio.h> #include <stdio.h> #include <process.h> struct stu { int std_ID; char name[20]; struct stu *next; } first=0,last=0; void main() { clrscr(); int b,key; while (1) { cout << "To enque press 1:"; cout<<"\n To deque press 2:"; cout<<"\nFor display press3"; cout<<"\nTo exit press4:" ; cout<<"\n"; cin >> b; switch (b) { //******insert in end***** case 1: { struct stu *current; current = new stu; current -> next = 0; if ( first== 0 ) { first= current; last = current; } else { last -> next = current; last = current; } cout << "\nStudent ID: "; cin >> current -> std_ID; cout << "\nInput Name: "; gets ( current -> name ); cout<<"\n\n"; break; } //******delete from start case 2:
struct stu *p; p=first; if(first==last) { cout<<"\nque is empty\n"; break; } else { if(first->next==0) { delete(p); } else { p=p->next; first->next=0; delete(first); first=p; } } break; } //****display case 3: { struct stu *p; p = first; while ( p != 0 ) { cout << "\nStudent's ID: " << p -> std_ID << "\nStudent's Name: "; puts ( p -> name ); cout<<"\n\n"; p = p -> next; } break; } //*****exit case 4: { exit(0); break; } } getch(); } }