-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathArrangeConsonantsAndVowels.java
50 lines (39 loc) · 1.23 KB
/
ArrangeConsonantsAndVowels.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
/*
Structure of node class is:
class Node {
char data;
Node next;
public Node(char data){
this.data = data;
next = null;
}
}
*/
class Solution {
public Node arrangeCV(Node head){
//write code here and return the head of changed linked list
Node traverseNode = head;
Node resultA = new Node('A');
Node resultAPointer = resultA;
Node resultB = new Node('A');
Node resultBPointer = resultB;
while(traverseNode != null){
if(traverseNode.data == 'a' || traverseNode.data == 'e' ||
traverseNode.data == 'i' || traverseNode.data == 'o' ||
traverseNode.data == 'u')
{
resultAPointer.next = new Node(traverseNode.data);
resultAPointer = resultAPointer.next;
}
else
{
resultBPointer.next = new Node(traverseNode.data);
resultBPointer = resultBPointer.next;
}
traverseNode = traverseNode.next;
}
resultB = resultB.next;
resultAPointer.next = resultB;
return resultA.next;
}
}