Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ea5340

Browse files
authored
Update StackOfLinkedList.java
1 parentd60f836 commit2ea5340

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

‎DataStructures/Stacks/StackOfLinkedList.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
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
Noden =newNode(x);
5553
if (head ==null) {
5654
head =n;
57-
}
58-
else {
55+
}else {
5956
Nodetemp =head;
6057
n.next =temp;
6158
head =n;
@@ -73,20 +70,19 @@ public void pop() {
7370
}
7471

7572
publicintpeek() {
76-
if (head ==null) {
77-
return -1;
78-
}
79-
returnhead.data;
73+
if (head ==null) {
74+
return -1;
75+
}
76+
returnhead.data;
8077
}
8178

8279
publicvoidprintStack() {
8380
Nodetemp =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
publicintgetSize() {
102-
if(head ==null)
98+
if(head ==null)
10399
return0;
104100
else {
105101
intsize =1;
106102
Nodetemp =head;
107-
while(temp.next !=null) {
103+
while(temp.next !=null) {
108104
temp =temp.next;
109105
size++;
110106
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp