Docsity

Linked List 1-Data Structures and Representation-Assigment, Exercises of Data Structures and Algorithms

Toggle sidebar
bg1
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <process.h>
struct stu
{
int std_ID;
char name[20];
float marks;
struct stu *next;
}
*first,*last;
void main()
{
clrscr();
int b;
first=0;
last=0;
while (1)
{
cout << "To insert values into the Linked List press 1:";
cout<<"\nToview the Data stored in the Linked List press 2:";
cout<<"\nTo exit press 3:" ;
cout<<"\n";
cin >> b;
switch (b)
{
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 << "\nInput Marks: ";
cin >> current -> marks;
break;
}
case 2:
{
struct stu *p;
docsity.com
pf2

Partial preview of the text

Download Linked List 1-Data Structures and Representation-Assigment and more Exercises Data Structures and Algorithms in PDF only on Docsity!

#include <iostream.h> #include <conio.h> #include <stdio.h> #include <process.h> struct stu { int std_ID; char name[20]; float marks; struct stu *next; } first,last; void main() { clrscr(); int b; first=0; last=0; while (1) { cout << "To insert values into the Linked List press 1:"; cout<<"\nToview the Data stored in the Linked List press 2:"; cout<<"\nTo exit press 3:" ; cout<<"\n"; cin >> b; switch (b) { 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 << "\nInput Marks: "; cin >> current -> marks; break; } case 2: { struct stu *p;

docsity.com

p = first; while ( p != 0 ) { cout << "\nStudent's ID: " << p -> std_ID << "\nStudent's Name: "; puts ( p -> name ); cout << "Student's Marks: " << p -> marks; cout<<"\n"; p = p -> next; } break; } case 3: { exit(0); } } getch(); } }

docsity.com