You are on page 1of 7

Single linked lists

public boolean Question


test (100)
Size 1
head
=

head

10 (Size
=
=
=

1) 108
I > 101 I
-

head
188

-
new Node

Size 4 =
public boolean Question
test (100)
head

1) -> 201 -

301 ->

40)
else
temp
head &
188
1) -> 201 -

301 40)
->

i
2
=

steps
for (i 0,i =
-

it
negy -> col -

P

head
5 -> -> 15
I
100
7 12 -
->

print i 5 100 1 12 IS

head
5 -> 100 -> 12 - 15
-
E
print: $100 12 IS 10
&
-
-

E
- SE
Larger (8,55); 2
+

list. Print And Replace +

include:
private data
member,temp
temp, data

E
Node(E) temp-head;
While (temp!=null)
S
if (((comparable) temp.data). Compareto ((comparable) value), 0) I

System. Out printh (temp.data);


temp, data replaceltem;3
=

else

temp:temp.next;33
E

Node (2) temp head; =

boolean found = false;


while (temp!-null SK! found)
If (temp. data value) = =

found true;
=

else

temp:temp.next;

If (found)
E
Noche (E) puev=temp;
temp-temp. next;3

While (temp!=null)
E if
(temp. data value) = =

E
puer, next:temp, next;
temp-
temp, next;
size--;
3
else E

prev=temp;
temp.next;333
temp=
E
remove All (10)
(head null);
-strut
If =
=

return;
while null 8
(head!I head data == value)
E
Prev
Ptr
head
head-head. next;

Size --;
- -
-
t
3

Node (2)
prev, ptr,
⑪-
head

prer-head,
ptr=puev.next;

While
(ptr!=null) E -
If (ptr. data value)
==

E
prev, next =
ptr.next;

Ptu
next

3
elseE
prev=ptr;
ptr ptr.next;
=

3
-unindex co II index> size -

public void Swapiters (int index, int index2)


E
(index 1 <0
If I indexic = Size 11 index20 11 Index 2)
Size)
=

throw new Index Outof BoundsException ();


Node (E) ptrl-head;

&(int i 0;i
=

< index't;i + +)
ptr1=part, next;
Node (E) ptr2=head;
for (inti 0;i<induxz; itt)
=

ptrz=ptr. next;
E temp ptr 1. data;
=

ptr1, data ptr2, data; =

ptrz.data: temp;

You might also like