I have given the input AMAZON through a linked list.Output should be AAOMZN.ie vowels at front and consonants at back.Netbeans IDE isn’t showing any output.Please point out error if any.Why is the IDE not showing any output.
My code :
class Node
{
char value;
Node next;
}
public class AmazonProb1
{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
String str=s.nextLine();
StringTokenizer ss=new StringTokenizer(str);
Node a1=new Node();
Node a2=new Node();
Node a3=new Node();
Node a4=new Node();
Node a5=new Node();
Node a6=new Node();
a1.value='A';
a2.value='M';
a3.value='A';
a4.value='Z';
a5.value='O';
a6.value='N';
a1.next=a2;
a2.next=a3;
a3.next=a4;
a4.next=a5;
a5.next=a6;
a6.next=null;
Node x=new Node();
Node head=new Node();
head=a1;
x=a1;
for(int i=0;i<6;i++)
{
if(head.value==(('A')|('O')|('E')|('I')|('U')))
{
head=head.next;
}
else if(head.value!=(('A')|('O')|('E')|('I')|('U')))
{
x=head;
while(head.value!=(('A')|('O')|('E')|('I')|('U')))
{
x=x.next;
}
swap(x,head);
}
}
System.out.println(a1);
System.out.println(a2);
System.out.println(a3);
System.out.println(a4);
System.out.println(a5);
System.out.println(a6);
}
public static void swap(Node a,Node b)
{
Node temp=new Node();
temp=a;
a=b;
b=temp;
}
}
You’re printing out the node, not node.value. Also, you don’t need to create a new node for Temp before assigning it b. b is already a reference to a node. You do not need another.