File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change 11/**
2- *
32 * @author Varun Upadhyay (https://github.com/varunu28)
4- *
53 */
64
75// An implementation of a Stack using a Linked List
@@ -42,7 +40,7 @@ public Node(int data) {
4240
4341/**
4442 * A class which implements a stack using a linked list
45- *
43+ * <p>
4644 * Contains all the stack methods : push, pop, printStack, isEmpty
4745 **/
4846
@@ -54,8 +52,7 @@ public void push(int x) {
5452 Node n = new Node (x );
5553 if (head == null ) {
5654 head = n ;
57- }
58- else {
55+ } else {
5956 Node temp = head ;
6057 n .next = temp ;
6158 head = n ;
@@ -73,20 +70,19 @@ public void pop() {
7370 }
7471
7572 public int peek () {
76- if (head == null ) {
77- return -1 ;
78- }
79- return head .data ;
73+ if (head == null ) {
74+ return -1 ;
75+ }
76+ return head .data ;
8077 }
8178
8279 public void printStack () {
8380 Node temp = head ;
8481 System .out .println ("Stack is printed as below: " );
8582 while (temp != null ) {
86- if (temp .next == null ) {
83+ if (temp .next == null ) {
8784 System .out .print (temp .data );
88- }
89- else {
85+ } else {
9086 System .out .print (temp .data + " -> " );
9187 }
9288 temp = temp .next ;
@@ -99,12 +95,12 @@ public boolean isEmpty() {
9995 }
10096
10197 public int getSize () {
102- if (head == null )
98+ if (head == null )
10399 return 0 ;
104100 else {
105101 int size = 1 ;
106102 Node temp = head ;
107- while (temp .next != null ) {
103+ while (temp .next != null ) {
108104 temp = temp .next ;
109105 size ++;
110106 }
You can’t perform that action at this time.
0 commit comments