Skip to main content

OOP

21.Problem statement

 Write C++ program using STL for implementation of stack & queue using SLL

Program

#include<iostream>
#include<stack>
#include<stdlib.h>
using namespace std;

void display(stack<int>s)
{

cout<<"\nElement in stack are:- ";
while(!s.empty())
{
cout<<s.top()<<"  ";
s.pop();
}
}



int main()
{
stack<int>s;
int choice,t;
int x;

while(1)
{
cout<<"\n\n*********************************";
cout<<"\n        STACK USING STL";
cout<<"\n*********************************";
cout<<"\n\n1.Push data";
cout<<"\n2.Pop data";
cout<<"\n3.Size of stack";
cout<<"\n4.First Element";
cout<<"\n5.Display Element in stack";
cout<<"\n6.Exit";
cout<<"\nEnter Your choice:- ";
cin>>choice;



    switch(choice)
    {

case 1:
cout<<"\nEnter Value to be insert:- ";
cin>>x;
s.push(x);
break;

case 2:
x=s.top();
s.pop();
cout<<"\nElement"<<x<<"Deleted from stack";
break;

case 3:
cout<<"\nSize of stack:- "<<s.size();
break;

case 4:
cout<<"\nTop Element of Stack:- "<<s.top();
break;

case 5:
display(s);
break;

case 6:
exit(1);
break;
    }
}
return 0;
}


Comments

Popular posts from this blog

OOP

6.Problem statement Develop an object oriented program in C++ to create a database of student  information system containing the following information: Name, Roll number, Class, division, Date of Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, Copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete. Program #include<iostream> #include<stdio.h> #include<cstring> using namespace std; class personal; static int count; class person {       char *name;       int *rollno,*classno;       char *bloodgroup,*div;                   public:person()              {     ...

DSL

9: Program Setatement A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...