generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshehe.java
74 lines (73 loc) · 1.73 KB
/
shehe.java
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
import java.util.Scanner;
class node{
char data;
node next;
public node(char data){
this.data = data;
next = null;
}
public void display_node(){
System.out.println(this.data);
}
}
class sll{
node head;
public sll(){
head = null;
}
public void insert(char data){
node nl = new node(data);
if(head == null){
head = nl;
nl.next = null;
}
else{
node current = head;
while(current.next != null){
current = current.next;
}
current.next = nl;
nl.next = null;
}
}
public void replace(){
node current = head;
while(current != null){
if(current.data == 's'){
node temp1 = current;
current = current.next;
if(current.data == 'h'){
node temp2 = current;
current = current.next;
if(current.data == 'e'){
node temp3 = current;
current = current.next;
temp1.data = 'h';
temp2.data = 'i';
temp3.data = 's';
}
}
}
else{
current = current.next;
}
}
}
public void display_list(){
for(node current = head;current != null;current = current.next){
current.display_node();
}
}
}
class shehe{
public static void main(String args[]){
sll s = new sll();
s.insert('a');
s.insert('s');
s.insert('h');
s.insert('e');
s.display_list();
s.replace();
s.display_list();
}
}