creating stacks

Solutions on MaxInterview for creating stacks by the best coders in the world

showing results for - "creating stacks"
Max
06 Jan 2020
1#include <iostream>
2#include <stack>
3using namespace std;
4class Student{
5    public:
6    string N, S;
7    int M;
8    Student(){
9	
10	}
11    Student(string N, string S, int M){
12        this->N = N;
13        this->S = S;
14        this->M = M;
15    }
16    void show(){
17        cout<<"Name: "<<this->N<<endl;
18        cout<<"Surname: "<<this->S<<endl;
19        cout<<"Marks: "<<this->M<<endl<<endl;
20    }
21};
22int main(){
23    stack<Student> St3, St2, St1;
24    St1.push(Student("Sam", "Williams", 60));
25    St1.push(Student("John", "Phoenix", 85));
26    St1.push(Student("Simon", "Johnson", 75));
27    St1.push(Student("Sarah", "Khosa", 81));
28    St1.push(Student("Mat", "Jackson", 38));
29    St1.push(Student("Nick", "Roberts", 26));
30    St1.push(Student("Isaac", "Wayne", 74));
31    St1.push(Student("Anna", "Mishima", 34));
32    St1.push(Student("Daniel", "Rose", 64));
33    St1.push(Student("Aaron", "Black", 83));
34    St1.push(Student("Jack", "Mohamed", 27));
35    St1.push(Student("Kathrine", "Bruckner", 42));
36
37
38    Student S1;
39    cout<<"Displaying contents of Stack 3\n";
40    while(!St1.empty()){
41        S1 = St1.top();
42        S1 .show();
43        St3.push(S1 );
44        St1.pop();
45    }
46    while(!St3.empty()){
47        St1.push(St3.top());
48        St3.pop();
49    }
50    while(!St1.empty()){
51        S1  = St1.top();
52        if(S1.S[0] == 'R' || S1.S[0] == 'J' || S1.S[0] == 'M'){
53            St2.push(S1);
54        }
55        St3.push(S1);
56        St1.pop();
57    }
58    cout<<"Displaying contents of Stack 2\n";
59    while(!St2.empty()){
60        S1 = St2.top();
61        S1.show();
62        St2.pop();
63    }
64    return 0;
similar questions
queries leading to this page
creating stacks