Skip to content

Commit

Permalink
Create Arrange consonants and vowels
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored May 1, 2024
1 parent 561383b commit abbd2ee
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions Arrange consonants and vowels
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//Arrange consonants and vowels

import java.io.*;
import java.util.*;

class Node {
char data;
Node next;

public Node(char data){
this.data = data;
next = null;
}
}

class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();

while(t-- > 0) {
int n = sc.nextInt();
Node head = null, tail = null;

char head_c = sc.next().charAt(0);
head = new Node(head_c);
tail = head;

while(n-- > 1) {
tail.next = new Node(sc.next().charAt(0));
tail = tail.next;
}

Solution obj = new Solution();
show(obj.arrangeCV(head));

}
}

public static void po(Object o) {
System.out.println(o);
}

public static void show(Node head) {
while(head != null) {
System.out.print(head.data+" ");
head = head.next;
}
System.out.println();
}
}

Structure of node class is:
class Node {
char data;
Node next;

public Node(char data) {
this.data = data;
next = null;
}
}

Solution {
public Node arrangeCV(Node head){
Node vowel = new Node('a'), con = new Node('b');
Node vowelH = vowel, conH = con;

while(head != null) {
char temp = head.data;

if(temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u') {
vowel.next = head;
vowel = vowel.next;
}

else {
con.next = head;
con = con.next;
}

head = head.next;
}

con.next = null;
vowel.next = conH.next;

return vowelH.next;
}
}

0 comments on commit abbd2ee

Please sign in to comment.