FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-basics/core-java/collections/StackExample.java at master · CodeForHunger/java-basics · GitHub
CodeForHunger
/
java-basics
Public
forked from
learning-zone/java-basics
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-basics
/
core-java
/
collections
/
StackExample.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (43 loc) · 1.23 KB
Breadcrumbs
java-basics
/
core-java
/
collections
/
StackExample.java
Copy path
File metadata and controls
50 lines (43 loc) · 1.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
collections
;
import
java
.
util
.
Stack
;
public
class
StackExample
{
// Pushing element on the top of stack
static
void
stack_push
(
Stack
<
Integer
>
stack
) {
System
.
out
.
println
(
"Push: "
);
for
(
int
i
=
0
;
i
<
5
;
i
++){
stack
.
push
(
i
);
System
.
out
.
print
(
i
+
", "
);
}
}
// Popping element from the top of the stack
static
void
stack_pop
(
Stack
<
Integer
>
stack
) {
System
.
out
.
println
(
"
\n
Pop: "
);
for
(
int
i
=
0
;
i
<
5
;
i
++) {
Integer
y
= (
Integer
)
stack
.
pop
();
System
.
out
.
print
(
y
+
", "
);
}
}
// Displaying element on the top of the stack
static
void
stack_peek
(
Stack
<
Integer
>
stack
) {
Integer
element
= (
Integer
)
stack
.
peek
();
System
.
out
.
println
(
"
\n
Element on stack top: "
+
element
);
}
// Searching element in the stack
static
void
stack_search
(
Stack
<
Integer
>
stack
,
int
element
) {
Integer
pos
= (
Integer
)
stack
.
search
(
element
);
if
(
pos
== -
1
){
System
.
out
.
println
(
element
+
" not found in stack "
);
}
else
{
System
.
out
.
println
(
element
+
" found at position: "
+
pos
);
}
}
public
static
void
main
(
String
[]
args
) {
Stack
<
Integer
>
stack
=
new
Stack
<
Integer
>();
stack_push
(
stack
);
stack_pop
(
stack
);
stack_push
(
stack
);
stack_peek
(
stack
);
stack_search
(
stack
,
2
);
stack_search
(
stack
,
6
);
}
}
Back
|
FazBrowse Home
|
New Git URL