-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStacks.html
98 lines (87 loc) · 3.42 KB
/
Stacks.html
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<link rel="stylesheet" href="Arrays.css">
<title>Stacks</title>
</head>
<body>
<nav>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<i class="fas fa-bars"></i>
</label>
<label class="logo">Codeinfo</label>
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li><a href="Arrays.html">Arrays</a></li>
<li><a href="Stacks.html">Stacks</a></li>
<li><a href="queues.html">Queues</a></li>
<li><a href="LinkedList.html">Linkedlist</a></li>
<li><a href="Heaps.html">Heaps</a></li>
<li><a href="Trees.html">Trees</a></li>
</ul>
</nav>
<div class = "matter">
<h1><strong>Stacks</strong></h1> <br>
<p>Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).</p>
<!-- <img src="Linkedlist.png" alt=""> -->
<br><br>
<p>Stacks are a type of container adaptors with LIFO(Last In First Out) type of working, where a new element is added at one end and (top) an element is removed from that end only. Stack uses an encapsulated object of either vector or deque (by default) or list (sequential container class) as its underlying container, providing a specific set of member functions to access its elements.</p>
<br>
<br>
<h3><strong>The functions associated with stack are: </strong></h3><br>
<!-- <p><br><br> -->
empty() – Returns whether the stack is empty – Time Complexity : O(1) <br><br>
size() – Returns the size of the stack – Time Complexity : O(1) <br><br>
top() – Returns a reference to the top most element of the stack – Time Complexity : O(1) <br><br>
push(g) – Adds the element ‘g’ at the top of the stack – Time Complexity : O(1) <br><br>
pop() – Deletes the top most element of the stack – Time Complexity : O(1) </p><br><br>
<pre><code>
// CPP program to demonstrate working of STL stack
#include <bits/stdc++.h>
using namespace std;
void showstack(stack <int> s)
{
while (!s.empty())
{
cout << '\t' << s.top();
s.pop();
}
cout << '\n';
}
int main ()
{
stack <int> s;
s.push(10);
s.push(30);
s.push(20);
s.push(5);
s.push(1);
cout << "The stack is : ";
showstack(s);
cout << "\ns.size() : " << s.size();
cout << "\ns.top() : " << s.top();
cout << "\ns.pop() : ";
s.pop();
showstack(s);
return 0;
}
</code></pre>
<footer>
<div class="footer-content">
<h3>codeinfo</h3>
<p>Learn to code with our beginner-friendly tutorials and examples. Read tutorials, try examples, write programs, and learn to code.</p>
<ul class="socials">
</ul>
</div>
<div class="footer-bottom">
<p>copyright ©2021 codeinfo. designed by <span>nithin</span></p>
</div>
</footer>
</body>
</html>