Categories
Uncategorised

Stacks : Implementation Using Linked Lists

/* Copyright (C) 2007 Ankur Banerjee. This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html /

/ Linked List implementation of a Stack /

#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>

class student
{
int rno;
char nm[42];
float perc;
public:
student *next;
void getdata()
{
cout<<endl<<“Enter roll number:”;
cin>>rno;
cout<<“Enter name: “;
gets(nm);
cout<<“Enter percentage: “;
cin>>perc;
next = NULL;
}
void showdata()
{
cout<<endl<<“Roll number: “<<rno
<<endl<<“Name: “<<nm
<<endl<<“Percentage: “<<perc<<endl;
}
};

void main()
{
int ch;
char choice;
student *newptr, *top = NULL, *ptr;
do
{
clrscr();
cout<<endl<<“Program Menu”
<<endl<<“1. Push (insert)”
<<endl<<“2. Pop (delete)”
<<endl<<“3. Traverse (show whole list)”
<<endl<<“4. Exit program”
<<endl<<“Enter your choice: “;
cin>>ch;
switch(ch)
{
case 1 :
clrscr();
newptr = new student;
if (!newptr)
{
cout<<endl<<“Memory allocation error! Exiting program”;
exit(0);
}
newptr->getdata();
if (top == NULL)
{
top = newptr;
}
else
{
newptr->next = top;
top = newptr;
}
break;
case 2 :
if (top == NULL)
cout<<endl<<“Error! Stack does not exist!”;
else
{
ptr = top;
top = top->next;
}
cout<<endl<<“Showing details of deleted element:”;
ptr->showdata();
delete ptr;
break;
case 3 :
ptr = top;
if (top == NULL)
cout<<endl<<“Error! Stack does not exist!”;
else
{
while (ptr != NULL)
{
ptr->showdata();
ptr = ptr->next;
}
}
break;
case 4 : cout<<endl<<“Exiting program”;
exit(0);
default :
cout<<endl<<“You entered an invalid choice!”;
}
cout<<endl<<“Do you wish to continue? (y/n): “;
cin>>choice;
}
while (choice == ‘Y’ || choice == ‘y’);
}

/ Output */

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 1

Enter roll number: 42
Enter name: Ankur Banerjee
Enter percentage: 42

Do you wish to continue? (y/n): y

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 1

Enter roll number: 10
Enter name: Arthur Dent
Enter percentage: 96

Do you wish to continue? (y/n): y

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 3

Roll number: 10
Name: Arthur Dent
Percentage: 96

Roll number: 42
Name: Ankur Banerjee
Percentage: 42

Do you wish to continue? (y/n): y

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 2

Showing details of deleted element:
Roll number: 10
Name: Arthur Dent
Percentage: 96

Do you wish to continue? (y/n): y

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 3

Roll number: 42
Name: Ankur Banerjee
Percentage: 42

Do you wish to continue? (y/n): y

Program Menu
1. Push (insert)
2. Pop (delete)
3. Traverse (show whole list)
4. Exit program
Enter your choice: 4

Exiting program

Categories
Uncategorised

Lest They Change The Board Next Year…

Engineers India Limited, happens to be this real fun joint you know, which has their office in Bhikaji Cama Place (I hope the it’s not renamed after some freedom fighter by the time I reach home), a place quite close to my house. Here’s what Ze Wiki has to say about it…

Engineers India Limited (EIL) is a public-listed company under the Ministry of Petroleum and Natural Gas, and is a business enterprise of the Government of India that was initially set up in 1965 to help the vital petroleum industry in the country. It has to its credit, more than 4,300 assignments, including 320 major projects, that has, so far, been successfully completed.

Notice the year which is BOLD in the above paragraph? Now if I’m not wrong, then this board belongs to EIL…

Engineers India Limited board

“Please press 2 to change your preferred language…”

Engineers India Limited board (Hindi)And in case you STILL happen to be a dimwitted twit who did NOT get what the fuss was…

Engineers India Limited board (marked)I thought I should take a pic of this today for posterity; who knows, if they decide to change the board next year… 😐