C++ In this project you will implement two small programs. One program will show an example of stack use and another program will show the use of a Queue 1. Use the STL to create your data structures 2. You should have the following features: a. Add a record b. Find a record

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
C++ In this project you will implement two small programs. One program will show an example of stack use and another program will show the use of a Queue 1. Use the STL to create your data structures 2. You should have the following features: a. Add a record b. Find a record c. Delete a record e. View all records
Expert Solution
Step 1

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
//Function to print the Maximum element in the stack
void findstack(stack<int> s)
{
    int m = s.top(); //initialization

    int a;
int n;
   
        cout<<"Enter value to find:";
       cin >> a;
while(!s.empty())
{
        if (m==a)
        {n=1;
        }
s.pop();
}
if(n==1)
{
    cout << "Element is found";
}
 else
 {
                cout<<"Not found";
            }
            
}

//Function to print the elements of the stack
void show(stack<int> s)
{
    while (!s.empty())
    {
        cout << "  " << s.top(); //printing the topmost element
        s.pop();                 //removing the topmost element to bring next element at the top
    }
    cout << endl;
}

int main()
{
    int i;
    //Stack declaration (stack of integers)
    stack<int> s;
    //Filling the elements by using the push() method.
    cout << "Filling the Stack in LIFO order using the push() method:"; //LIFO= Last In First Out
    s.push(4);
    s.push(2);
    s.push(20);
    s.push(12);
    s.push(52);
    s.push(14);
    cout << "\n\nThe elements of the Stack in LIFO order are: ";
    show(s);
    findstack(s); //to find the stack element
    cout << "\n\n\n";
    return 0;
}

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education