-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverse.cpp
More file actions
55 lines (47 loc) · 1.14 KB
/
reverse.cpp
File metadata and controls
55 lines (47 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
using namespace std;
#include<stack>
stack<int> s;
void input(){
/*
Objective: This function takes a number as a input and pushes it in a stack.
Input parameters: None
Output: None
Side effects: Size of the stack is increased by 1 as a number is pushed to it.
Return Value: None
*/
int x;
cout<<"\nEnter number : ";
cin>>x;
s.push(x);
}
void reverse(){
/*
Objective: This function prints the number in the stack in reverse order.
Input parameter: None
Functions used: empty() -> returns True if stack is empty, otherwise False.
top() -> returns top element of the stack.
pop() -> removes the top element from the stack
Return value: None
Side effects: The stack has been emptied.
*/
cout<<"\n\t\tNumber in reverse order";
while(!s.empty()){
cout<<"\n"<<s.top();
s.pop();
}
}
int main(){
/*
objective: To reverse given set of numbers using function input() and reverse()
*/
cout<<"\n\t\tPROGRAM TO REVERSE A NUMBER";
int n;
cout<<"\n\nHow many number do you want: ";
cin>>n;
while(n--!=0){
input();
}
reverse();
return 0;
}