Arrange consonants and vowels nodes in a linked list

Here given code implementation process.

// C Program 
// Arrange consonants and vowels nodes in a linked list
#include <stdio.h>

#include <stdlib.h> //for malloc function

// Linked List LinkNode
struct LinkNode
{
    char data;
    struct LinkNode *next;
};
// Singly linked list 
struct SingleLL
{
    struct LinkNode *head;
    struct LinkNode *tail;
};
// Returns the new linked list
struct SingleLL *newLinkedList()
{
    // Create memory of head and tail Nodes
    struct SingleLL *sll = (struct SingleLL *) malloc(sizeof(struct SingleLL));
    if (sll == NULL)
    {
        printf("Memory overflow\n");
    }
    else
    {
        sll->head = NULL;
        sll->tail = NULL;
    }
    return sll;
}

// Add new Node at end of linked list 
void appendNode(struct SingleLL *sll,struct LinkNode *node )
{
    if (sll->head == NULL)
    {
        sll->head = node;
    }
    else
    {
        // Append the node at last position
        sll->tail->next = node;
    }
    sll->tail = node;
}


// Handles the request of adding new node in linked list
void addNode(struct SingleLL *sll, char data)
{
    // Create dynamic node
    struct LinkNode *node = (struct LinkNode *) malloc(sizeof(struct LinkNode));
    if (node == NULL)
    {
        printf("Memory overflow to Create LinkNode\n");
        return;
    }
    else
    {
        // Set initial node value
        node->data = data;
        node->next = NULL;
    }    
    appendNode(sll,node);
}


// Display linked list element
void display(struct SingleLL *sll)
{
    if (sll->head == NULL)
    {
        printf("\n Empty linked list\n");
        return;
    }
    struct LinkNode *temp = sll->head;
    // iterating linked list elements
    while (temp != NULL)
    {
        printf(" %c →", temp->data);
        // Visit to next node
        temp = temp->next;
    }
    printf(" NULL\n");
}

// Determine that given value is an vowel or not
int isVowels( char value)
{
    if(value=='a' || value=='e' || value=='i'|| value=='o'|| value=='u'
     || value=='A'|| value=='E' || value=='I'|| value=='O'|| value=='U')
    {
        return 1;
    }
    return 0;
}
//  Arrange the nodes in front position of vowels and end with consonants
void arrangeNodes(struct SingleLL *sll)
{
    if (sll->head == NULL)
    {
        printf("\n Empty linked list\n");
        return;
    }
    // Define some auxiliary variable
    struct SingleLL *vowel      =  newLinkedList();
    struct SingleLL *consonant  =  newLinkedList();

    struct LinkNode*auxiliary   = sll->head;
    struct LinkNode*ordinary   = sll->head;

    // iterate linked list nodes
    while(auxiliary != NULL )
    {

        ordinary = auxiliary;

        auxiliary = auxiliary->next;

        if(isVowels(ordinary->data)== 1 )
        {
            // Add node into volwel list
            appendNode(vowel,ordinary);
        }
        else
        {
            appendNode(consonant,ordinary);
        }

        ordinary->next = NULL;
    }
    if(vowel->head != NULL)
    {
        // Set new head node of resultant linked list
        sll->head = vowel->head;

        // Connect vowel and consonant linked list
        vowel->tail->next = consonant->head;
        
        if(consonant->tail != NULL)
        {
            // When consonant node exists
            // Set new tail node of resultant linked list 
            sll->tail = consonant->tail;
        }
        else
        {
            // When consonant nodes not exists
            sll->tail = vowel->tail;
        }
    }
    else
    {
        // When vowels not exist
        sll->head = consonant->head;
        sll->tail - consonant->tail;
    }
}
int main()
{
    // Define linked list
    struct SingleLL *sll = newLinkedList();


    // Constructed linked list
    addNode(sll, 'R');
    addNode(sll, 'E');
    addNode(sll, 'G');
    addNode(sll, 'U');
    addNode(sll, 'L');
    addNode(sll, 'A');
    addNode(sll, 'T');
    addNode(sll, 'I');
    addNode(sll, 'O');
    addNode(sll, 'N');
    printf(" Before Arrange \n");
    // R → E → G → U → L → A → T → I → O → N → NULL
    display(sll);

    arrangeNodes(sll);

    printf(" After Arrange \n");
    // E → U → A → I → O → R → G → L → T → N → NULL
    display(sll);
 
    return 0;
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
/*
  Java Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	public char data;
	public LinkNode next;
	public LinkNode(char data)
	{
		this.data = data;
		this.next = null;
	}
}
public class SingleLL
{
	public LinkNode head;
	public LinkNode tail;
	public SingleLL()
	{
		this.head = null;
		this.tail = null;
	}
	// Add new Node at end of linked list 
	public void appendNode(LinkNode node)
	{
		if (this.head == null)
		{
			this.head = node;
		}
		else
		{
			// Append the node at last position
			this.tail.next = node;
		}
		this.tail = node;
	}
	// Handles the request of adding new node in linked list
	public void addNode(char data)
	{
		LinkNode node = new LinkNode(data);
		this.appendNode(node);
	}
	// Display linked list element
	public void display()
	{
		if (this.head == null)
		{
			System.out.print("\n Empty linked list\n");
			return;
		}
		LinkNode temp = this.head;
		//iterating linked list elements
		while (temp != null)
		{
			System.out.print(" " + temp.data + " →");
			// Visit to next node
			temp = temp.next;
		}
		System.out.print(" NULL\n");
	}
	// Determine that given value is an vowel or not
	public boolean isVowels(char value)
	{
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' || 
            value == 'u' || value == 'A' || 
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	public void arrangeNodes()
	{
		if (this.head == null)
		{
			System.out.print("\n Empty linked list\n");
			return;
		}
		// Define some auxiliary variable
		SingleLL vowel = new SingleLL();
		SingleLL consonant = new SingleLL();
		LinkNode auxiliary = this.head;
		LinkNode ordinary = null;
		// iterate linked list nodes
		while (auxiliary != null)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary.next;
			if (isVowels(ordinary.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary.next = null;
		}
		if (vowel.head != null)
		{
			// Set new head node of resultant linked list
			this.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail.next = consonant.head;
			if (consonant.tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list 
				this.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this.head = consonant.head;
			this.tail = consonant.tail;
		}
	}
	public static void main(String[] args)
	{
		SingleLL sll = new SingleLL();
		// Constructed linked list
		sll.addNode('R');
		sll.addNode('E');
		sll.addNode('G');
		sll.addNode('U');
		sll.addNode('L');
		sll.addNode('A');
		sll.addNode('T');
		sll.addNode('I');
		sll.addNode('O');
		sll.addNode('N');
		System.out.print(" Before Arrange \n");
		// R → E → G → U → L → A → T → I → O → N → NULL
		sll.display();
		sll.arrangeNodes();
		System.out.print(" After Arrange \n");
		// E → U → A → I → O → R → G → L → T → N → NULL
		sll.display();
	}
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
// Include header file
#include <iostream>

using namespace std;
/*
  C++ Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	public: char data;
	LinkNode *next;
	LinkNode(char data)
	{
		this->data = data;
		this->next = NULL;
	}
};
class SingleLL
{
	public: LinkNode *head;
	LinkNode *tail;
	SingleLL()
	{
		this->head = NULL;
		this->tail = NULL;
	}
	// Add new Node at end of linked list
	void appendNode(LinkNode *node)
	{
		if (this->head == NULL)
		{
			this->head = node;
		}
		else
		{
			// Append the node at last position
			this->tail->next = node;
		}
		this->tail = node;
	}
	// Handles the request of adding new node in linked list
	void addNode(char data)
	{
		LinkNode *node = new LinkNode(data);
		this->appendNode(node);
	}
	// Display linked list element
	void display()
	{
		if (this->head == NULL)
		{
			cout << "\n Empty linked list\n";
			return;
		}
		LinkNode *temp = this->head;
		//iterating linked list elements
		while (temp != NULL)
		{
			cout << " " << temp->data << " →";
			// Visit to next node
			temp = temp->next;
		}
		cout << " NULL\n";
	}
	// Determine that given value is an vowel or not
	bool isVowels(char value)
	{
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' || 
            value == 'u' || value == 'A' || 
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	void arrangeNodes()
	{
		if (this->head == NULL)
		{
			cout << "\n Empty linked list\n";
			return;
		}
		// Define some auxiliary variable
		SingleLL vowel = SingleLL();
		SingleLL consonant = SingleLL();
		LinkNode *auxiliary = this->head;
		LinkNode *ordinary = NULL;
		// iterate linked list nodes
		while (auxiliary != NULL)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary->next;
			if (this->isVowels(ordinary->data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary->next = NULL;
		}
		if (vowel.head != NULL)
		{
			// Set new head node of resultant linked list
			this->head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail->next = consonant.head;
			if (consonant.tail != NULL)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				this->tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this->tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this->head = consonant.head;
			this->tail = consonant.tail;
		}
	}
};
int main()
{
	SingleLL sll = SingleLL();
	// Constructed linked list
	sll.addNode('R');
	sll.addNode('E');
	sll.addNode('G');
	sll.addNode('U');
	sll.addNode('L');
	sll.addNode('A');
	sll.addNode('T');
	sll.addNode('I');
	sll.addNode('O');
	sll.addNode('N');
	cout << " Before Arrange \n";
	// R → E → G → U → L → A → T → I → O → N → NULL
	sll.display();
	sll.arrangeNodes();
	cout << " After Arrange \n";
	// E → U → A → I → O → R → G → L → T → N → NULL
	sll.display();
	return 0;
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
// Include namespace system
using System;
/*
  C# Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
public class LinkNode
{
	public char data;
	public LinkNode next;
	public LinkNode(char data)
	{
		this.data = data;
		this.next = null;
	}
}
public class SingleLL
{
	public LinkNode head;
	public LinkNode tail;
	public SingleLL()
	{
		this.head = null;
		this.tail = null;
	}
	// Add new Node at end of linked list
	public void appendNode(LinkNode node)
	{
		if (this.head == null)
		{
			this.head = node;
		}
		else
		{
			// Append the node at last position
			this.tail.next = node;
		}
		this.tail = node;
	}
	// Handles the request of adding new node in linked list
	public void addNode(char data)
	{
		LinkNode node = new LinkNode(data);
		this.appendNode(node);
	}
	// Display linked list element
	public void display()
	{
		if (this.head == null)
		{
			Console.Write("\n Empty linked list\n");
			return;
		}
		LinkNode temp = this.head;
		//iterating linked list elements
		while (temp != null)
		{
			Console.Write(" " + temp.data + " →");
			// Visit to next node
			temp = temp.next;
		}
		Console.Write(" NULL\n");
	}
	// Determine that given value is an vowel or not
	public Boolean isVowels(char value)
	{
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' || 
            value == 'u' || value == 'A' || 
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	public void arrangeNodes()
	{
		if (this.head == null)
		{
			Console.Write("\n Empty linked list\n");
			return;
		}
		// Define some auxiliary variable
		SingleLL vowel = new SingleLL();
		SingleLL consonant = new SingleLL();
		LinkNode auxiliary = this.head;
		LinkNode ordinary = null;
		// iterate linked list nodes
		while (auxiliary != null)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary.next;
			if (isVowels(ordinary.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary.next = null;
		}
		if (vowel.head != null)
		{
			// Set new head node of resultant linked list
			this.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail.next = consonant.head;
			if (consonant.tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				this.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this.head = consonant.head;
			this.tail = consonant.tail;
		}
	}
	public static void Main(String[] args)
	{
		SingleLL sll = new SingleLL();
		// Constructed linked list
		sll.addNode('R');
		sll.addNode('E');
		sll.addNode('G');
		sll.addNode('U');
		sll.addNode('L');
		sll.addNode('A');
		sll.addNode('T');
		sll.addNode('I');
		sll.addNode('O');
		sll.addNode('N');
		Console.Write(" Before Arrange \n");
		// R → E → G → U → L → A → T → I → O → N → NULL
		sll.display();
		sll.arrangeNodes();
		Console.Write(" After Arrange \n");
		// E → U → A → I → O → R → G → L → T → N → NULL
		sll.display();
	}
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
<?php
/*
  Php Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	public $data;
	public $next;

	function __construct($data)
	{
		$this->data = $data;
		$this->next = null;
	}
}
class SingleLL
{
	public $head;
	public $tail;

	function __construct()
	{
		$this->head = null;
		$this->tail = null;
	}
	// Add new Node at end of linked list
	public	function appendNode($node)
	{
		if ($this->head == null)
		{
			$this->head = $node;
		}
		else
		{
			// Append the node at last position
			$this->tail->next = $node;
		}
		$this->tail = $node;
	}
	// Handles the request of adding new node in linked list
	public	function addNode($data)
	{
		$node = new LinkNode($data);
		$this->appendNode($node);
	}
	// Display linked list element
	public	function display()
	{
		if ($this->head == null)
		{
			echo "\n Empty linked list\n";
			return;
		}
		$temp = $this->head;
		//iterating linked list elements
		while ($temp != null)
		{
			echo " ". $temp->data ." →";
			// Visit to next node
			$temp = $temp->next;
		}
		echo " NULL\n";
	}
	// Determine that given value is an vowel or not
	public	function isVowels($value)
	{
		if ($value == 'a' || $value == 'e' || 
            $value == 'i' || $value == 'o' || 
            $value == 'u' || $value == 'A' || 
            $value == 'E' || $value == 'I' || 
            $value == 'O' || $value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	public	function arrangeNodes()
	{
		if ($this->head == null)
		{
			echo "\n Empty linked list\n";
			return;
		}
		// Define some auxiliary variable
		$vowel = new SingleLL();
		$consonant = new SingleLL();
		$auxiliary = $this->head;
		$ordinary = null;
		// iterate linked list nodes
		while ($auxiliary != null)
		{
			$ordinary = $auxiliary;
			$auxiliary = $auxiliary->next;
			if ($this->isVowels($ordinary->data) == true)
			{
				// Add node into volwel list
				$vowel->appendNode($ordinary);
			}
			else
			{
				$consonant->appendNode($ordinary);
			}
			$ordinary->next = null;
		}
		if ($vowel->head != null)
		{
			// Set new head node of resultant linked list
			$this->head = $vowel->head;
			// Connect vowel and consonant linked list
			$vowel->tail->next = $consonant->head;
			if ($consonant->tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				$this->tail = $consonant->tail;
			}
			else
			{
				// When consonant nodes not exists
				$this->tail = $vowel->tail;
			}
		}
		else
		{
			// When vowels not exist
			$this->head = $consonant->head;
			$this->tail = $consonant->tail;
		}
	}
}

function main()
{
	$sll = new SingleLL();
	// Constructed linked list
	$sll->addNode('R');
	$sll->addNode('E');
	$sll->addNode('G');
	$sll->addNode('U');
	$sll->addNode('L');
	$sll->addNode('A');
	$sll->addNode('T');
	$sll->addNode('I');
	$sll->addNode('O');
	$sll->addNode('N');
	echo " Before Arrange \n";
	// R → E → G → U → L → A → T → I → O → N → NULL
	$sll->display();
	$sll->arrangeNodes();
	echo " After Arrange \n";
	// E → U → A → I → O → R → G → L → T → N → NULL
	$sll->display();
}
main();

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
/*
  Node Js Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	constructor(data)
	{
		this.data = data;
		this.next = null;
	}
}
class SingleLL
{
	constructor()
	{
		this.head = null;
		this.tail = null;
	}
	// Add new Node at end of linked list
	appendNode(node)
	{
		if (this.head == null)
		{
			this.head = node;
		}
		else
		{
			// Append the node at last position
			this.tail.next = node;
		}
		this.tail = node;
	}
	// Handles the request of adding new node in linked list
	addNode(data)
	{
		var node = new LinkNode(data);
		this.appendNode(node);
	}
	// Display linked list element
	display()
	{
		if (this.head == null)
		{
			process.stdout.write("\n Empty linked list\n");
			return;
		}
		var temp = this.head;
		//iterating linked list elements
		while (temp != null)
		{
			process.stdout.write(" " + temp.data + " →");
			// Visit to next node
			temp = temp.next;
		}
		process.stdout.write(" NULL\n");
	}
	// Determine that given value is an vowel or not
	isVowels(value)
	{
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' ||
            value == 'u' || value == 'A' ||
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	arrangeNodes()
	{
		if (this.head == null)
		{
			process.stdout.write("\n Empty linked list\n");
			return;
		}
		// Define some auxiliary variable
		var vowel = new SingleLL();
		var consonant = new SingleLL();
		var auxiliary = this.head;
		var ordinary = null;
		// iterate linked list nodes
		while (auxiliary != null)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary.next;
			if (this.isVowels(ordinary.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary.next = null;
		}
		if (vowel.head != null)
		{
			// Set new head node of resultant linked list
			this.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail.next = consonant.head;
			if (consonant.tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				this.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this.head = consonant.head;
			this.tail = consonant.tail;
		}
	}
}

function main()
{
	var sll = new SingleLL();
	// Constructed linked list
	sll.addNode('R');
	sll.addNode('E');
	sll.addNode('G');
	sll.addNode('U');
	sll.addNode('L');
	sll.addNode('A');
	sll.addNode('T');
	sll.addNode('I');
	sll.addNode('O');
	sll.addNode('N');
	process.stdout.write(" Before Arrange \n");
	// R → E → G → U → L → A → T → I → O → N → NULL
	sll.display();
	sll.arrangeNodes();
	process.stdout.write(" After Arrange \n");
	// E → U → A → I → O → R → G → L → T → N → NULL
	sll.display();
}
main();

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
#   Python 3 Program 
#   Arrange consonants and vowels nodes in a linked list

#  Linked list node
class LinkNode :
	
	def __init__(self, data) :
		self.data = data
		self.next = None
	

class SingleLL :
	
	def __init__(self) :
		self.head = None
		self.tail = None
	
	#  Add new Node at end of linked list 
	def appendNode(self, node) :
		if (self.head == None) :
			self.head = node
		else :
			#  Append the node at last position
			self.tail.next = node
		
		self.tail = node
	
	#  Handles the request of adding new node in linked list
	def addNode(self, data) :
		node = LinkNode(data)
		self.appendNode(node)
	
	#  Display linked list element
	def display(self) :
		if (self.head == None) :
			print("\n Empty linked list")
			return
		
		temp = self.head
		# iterating linked list elements
		while (temp != None) :
			print("", temp.data ,"→", end = "")
			#  Visit to next node
			temp = temp.next
		
		print(" NULL")
	
	#  Determine that given value is an vowel or not
	def isVowels(self, value) :
		if (value == 'a'
			or value == 'e'
			or value == 'i'
			or value == 'o'
			or value == 'u'
			or value == 'A'
			or value == 'E'
			or value == 'I'
			or value == 'O'
			or value == 'U') :
			return True
		
		return False
	
	#   Arrange the nodes in front position of vowels and end with consonants
	def arrangeNodes(self) :
		if (self.head == None) :
			print("\n Empty linked list")
			return
		
		#  Define some auxiliary variable
		vowel = SingleLL()
		consonant = SingleLL()
		auxiliary = self.head
		ordinary = None
		#  iterate linked list nodes
		while (auxiliary != None) :
			ordinary = auxiliary
			auxiliary = auxiliary.next
			if (self.isVowels(ordinary.data) == True) :
				#  Add node into volwel list
				vowel.appendNode(ordinary)
			else :
				consonant.appendNode(ordinary)
			
			ordinary.next = None
		
		if (vowel.head != None) :
			#  Set new head node of resultant linked list
			self.head = vowel.head
			#  Connect vowel and consonant linked list
			vowel.tail.next = consonant.head
			if (consonant.tail != None) :
				#  When consonant node exists
				#  Set new tail node of resultant linked list 
				self.tail = consonant.tail
			else :
				#  When consonant nodes not exists
				self.tail = vowel.tail
			
		else :
			#  When vowels not exist
			self.head = consonant.head
			self.tail = consonant.tail
		
	

def main() :
	sll = SingleLL()
	#  Constructed linked list
	sll.addNode('R')
	sll.addNode('E')
	sll.addNode('G')
	sll.addNode('U')
	sll.addNode('L')
	sll.addNode('A')
	sll.addNode('T')
	sll.addNode('I')
	sll.addNode('O')
	sll.addNode('N')
	print(" Before Arrange ")
	#  R → E → G → U → L → A → T → I → O → N → NULL
	sll.display()
	sll.arrangeNodes()
	print(" After Arrange ")
	#  E → U → A → I → O → R → G → L → T → N → NULL
	sll.display()

if __name__ == "__main__": main()

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
#   Ruby Program 
#   Arrange consonants and vowels nodes in a linked list

#  Linked list node
class LinkNode  
	# Define the accessor and reader of class LinkNode  
	attr_reader :data, :next
	attr_accessor :data, :next
 
	
	def initialize(data) 
		self.data = data
		self.next = nil
	end

end

class SingleLL  
	# Define the accessor and reader of class SingleLL  
	attr_reader :head, :tail
	attr_accessor :head, :tail
 
	
	def initialize() 
		self.head = nil
		self.tail = nil
	end

	#  Add new Node at end of linked list 
	def appendNode(node) 
		if (self.head == nil) 
			self.head = node
		else 
			#  Append the node at last position
			self.tail.next = node
		end

		self.tail = node
	end

	#  Handles the request of adding new node in linked list
	def addNode(data) 
		node = LinkNode.new(data)
		self.appendNode(node)
	end

	#  Display linked list element
	def display() 
		if (self.head == nil) 
			print("\n Empty linked list\n")
			return
		end

		temp = self.head
		# iterating linked list elements
		while (temp != nil) 
			print(" ", temp.data ," →")
			#  Visit to next node
			temp = temp.next
		end

		print(" NULL\n")
	end

	#  Determine that given value is an vowel or not
	def isVowels(value) 
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' || 
            value == 'u' || value == 'A' || 
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U') 
			return true
		end

		return false
	end

	#   Arrange the nodes in front position of vowels and end with consonants
	def arrangeNodes() 
		if (self.head == nil) 
			print("\n Empty linked list\n")
			return
		end

		#  Define some auxiliary variable
		vowel = SingleLL.new()
		consonant = SingleLL.new()
		auxiliary = self.head
		ordinary = nil
		#  iterate linked list nodes
		while (auxiliary != nil) 
			ordinary = auxiliary
			auxiliary = auxiliary.next
			if (self.isVowels(ordinary.data) == true) 
				#  Add node into volwel list
				vowel.appendNode(ordinary)
			else 
				consonant.appendNode(ordinary)
			end

			ordinary.next = nil
		end

		if (vowel.head != nil) 
			#  Set new head node of resultant linked list
			self.head = vowel.head
			#  Connect vowel and consonant linked list
			vowel.tail.next = consonant.head
			if (consonant.tail != nil) 
				#  When consonant node exists
				#  Set new tail node of resultant linked list 
				self.tail = consonant.tail
			else 
				#  When consonant nodes not exists
				self.tail = vowel.tail
			end

		else 
			#  When vowels not exist
			self.head = consonant.head
			self.tail = consonant.tail
		end

	end

end

def main() 
	sll = SingleLL.new()
	#  Constructed linked list
	sll.addNode('R')
	sll.addNode('E')
	sll.addNode('G')
	sll.addNode('U')
	sll.addNode('L')
	sll.addNode('A')
	sll.addNode('T')
	sll.addNode('I')
	sll.addNode('O')
	sll.addNode('N')
	print(" Before Arrange \n")
	#  R → E → G → U → L → A → T → I → O → N → NULL
	sll.display()
	sll.arrangeNodes()
	print(" After Arrange \n")
	#  E → U → A → I → O → R → G → L → T → N → NULL
	sll.display()
end

main()

Output

 Before Arrange 
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange 
 E → U → A → I → O → R → G → L → T → N → NULL
/*
  Scala Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode(var data: Character , var next: LinkNode)
{
	def this(data: Char)
	{
		this(data, null);
	}
}
class SingleLL(var head: LinkNode , var tail: LinkNode)
{
	def this()
	{
		this(null, null);
	}
	// Add new Node at end of linked list
	def appendNode(node: LinkNode): Unit = {
		if (this.head == null)
		{
			this.head = node;
		}
		else
		{
			// Append the node at last position
			this.tail.next = node;
		}
		this.tail = node;
	}
	// Handles the request of adding new node in linked list
	def addNode(data: Char): Unit = {
		var node: LinkNode = new LinkNode(data);
		this.appendNode(node);
	}
	// Display linked list element
	def display(): Unit = {
		if (this.head == null)
		{
			print("\n Empty linked list\n");
			return;
		}
		var temp: LinkNode = this.head;
		//iterating linked list elements
		while (temp != null)
		{
			print(" " + temp.data + " →");
			// Visit to next node
			temp = temp.next;
		}
		print(" NULL\n");
	}
	// Determine that given value is an vowel or not
	def isVowels(value: Char): Boolean = {
		if ( value == 'a' || value == 'e' || 
             value == 'i' || value == 'o' || 
             value == 'u' || value == 'A' || 
             value == 'E' || value == 'I' || 
             value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	def arrangeNodes(): Unit = {
		if (this.head == null)
		{
			print("\n Empty linked list\n");
			return;
		}
		// Define some auxiliary variable
		var vowel: SingleLL = new SingleLL();
		var consonant: SingleLL = new SingleLL();
		var auxiliary: LinkNode = this.head;
		var ordinary: LinkNode = null;
		// iterate linked list nodes
		while (auxiliary != null)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary.next;
			if (this.isVowels(ordinary.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary.next = null;
		}
		if (vowel.head != null)
		{
			// Set new head node of resultant linked list
			this.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail.next = consonant.head;
			if (consonant.tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				this.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this.head = consonant.head;
			this.tail = consonant.tail;
		}
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var sll: SingleLL = new SingleLL();
		// Constructed linked list
		sll.addNode('R');
		sll.addNode('E');
		sll.addNode('G');
		sll.addNode('U');
		sll.addNode('L');
		sll.addNode('A');
		sll.addNode('T');
		sll.addNode('I');
		sll.addNode('O');
		sll.addNode('N');
		print(" Before Arrange \n");
		// R → E → G → U → L → A → T → I → O → N → NULL
		sll.display();
		sll.arrangeNodes();
		print(" After Arrange \n");
		// E → U → A → I → O → R → G → L → T → N → NULL
		sll.display();
	}
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
/*
  Swift 4 Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	var data: Character;
	var next: LinkNode? ;
	init(_ data: Character)
	{
		self.data = data;
		self.next = nil;
	}
}
class SingleLL
{
	var head: LinkNode? ;
	var tail: LinkNode? ;
	init()
	{
		self.head = nil;
		self.tail = nil;
	}
	// Add new Node at end of linked list
	func appendNode(_ node: LinkNode? )
	{
		if (self.head == nil)
		{
			self.head = node;
		}
		else
		{
			// Append the node at last position
			self.tail!.next = node;
		}
		self.tail = node;
	}
	// Handles the request of adding new node in linked list
	func addNode(_ data: Character)
	{
		let node: LinkNode? = LinkNode(data);
		self.appendNode(node);
	}
	// Display linked list element
	func display()
	{
		if (self.head == nil)
		{
			print("\n Empty linked list");
			return;
		}
		var temp: LinkNode? = self.head;
		//iterating linked list elements
		while (temp  != nil)
		{
			print("", temp!.data ,"→", terminator: "");
			// Visit to next node
			temp = temp!.next;
		}
		print(" NULL");
	}
	// Determine that given value is an vowel or not
	func isVowels(_ value: Character)->Bool
	{
		if (value == "a" || value == "e" || 
            value == "i" || value == "o" || 
            value == "u" || value == "A" || 
            value == "E" || value == "I" || 
            value == "O" || value == "U")
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	func arrangeNodes()
	{
		if (self.head == nil)
		{
			print("\n Empty linked list");
			return;
		}
		// Define some auxiliary variable
		let vowel: SingleLL = SingleLL();
		let consonant: SingleLL = SingleLL();
		var auxiliary: LinkNode? = self.head;
		var ordinary: LinkNode? = nil;
		// iterate linked list nodes
		while (auxiliary  != nil)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary!.next;
			if (self.isVowels(ordinary!.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary!.next = nil;
		}
		if (vowel.head  != nil)
		{
			// Set new head node of resultant linked list
			self.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail!.next = consonant.head;
			if (consonant.tail  != nil)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				self.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				self.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			self.head = consonant.head;
			self.tail = consonant.tail;
		}
	}
}
func main()
{
	let sll: SingleLL = SingleLL();
	// Constructed linked list
	sll.addNode("R");
	sll.addNode("E");
	sll.addNode("G");
	sll.addNode("U");
	sll.addNode("L");
	sll.addNode("A");
	sll.addNode("T");
	sll.addNode("I");
	sll.addNode("O");
	sll.addNode("N");
	print(" Before Arrange ");
	// R → E → G → U → L → A → T → I → O → N → NULL
	sll.display();
	sll.arrangeNodes();
	print(" After Arrange ");
	// E → U → A → I → O → R → G → L → T → N → NULL
	sll.display();
}
main();

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL
/*
  Kotlin Program 
  Arrange consonants and vowels nodes in a linked list
*/
// Linked list node
class LinkNode
{
	var data: Char;
	var next: LinkNode ? ;
	constructor(data: Char)
	{
		this.data = data;
		this.next = null;
	}
}
class SingleLL
{
	var head: LinkNode ? ;
	var tail: LinkNode ? ;
	constructor()
	{
		this.head = null;
		this.tail = null;
	}
	// Add new Node at end of linked list
	fun appendNode(node: LinkNode ? ): Unit
	{
		if (this.head == null)
		{
			this.head = node;
		}
		else
		{
			// Append the node at last position
			this.tail?.next = node;
		}
		this.tail = node;
	}
	// Handles the request of adding new node in linked list
	fun addNode(data: Char): Unit
	{
		var node: LinkNode = LinkNode(data);
		this.appendNode(node);
	}
	// Display linked list element
	fun display(): Unit
	{
		if (this.head == null)
		{
			print("\n Empty linked list\n");
			return;
		}
		var temp: LinkNode ? = this.head;
		//iterating linked list elements
		while (temp != null)
		{
			print(" " + temp.data + " →");
			// Visit to next node
			temp = temp.next;
		}
		print(" NULL\n");
	}
	// Determine that given value is an vowel or not
	fun isVowels(value: Char): Boolean
	{
		if (value == 'a' || value == 'e' || 
            value == 'i' || value == 'o' || 
            value == 'u' || value == 'A' || 
            value == 'E' || value == 'I' || 
            value == 'O' || value == 'U')
		{
			return true;
		}
		return false;
	}
	//  Arrange the nodes in front position of vowels and end with consonants
	fun arrangeNodes(): Unit
	{
		if (this.head == null)
		{
			print("\n Empty linked list\n");
			return;
		}
		// Define some auxiliary variable
		var vowel: SingleLL = SingleLL();
		var consonant: SingleLL = SingleLL();
		var auxiliary: LinkNode ? = this.head;
		var ordinary: LinkNode?;
		// iterate linked list nodes
		while (auxiliary != null)
		{
			ordinary = auxiliary;
			auxiliary = auxiliary.next;
			if (this.isVowels(ordinary.data) == true)
			{
				// Add node into volwel list
				vowel.appendNode(ordinary);
			}
			else
			{
				consonant.appendNode(ordinary);
			}
			ordinary.next = null;
		}
		if (vowel.head != null)
		{
			// Set new head node of resultant linked list
			this.head = vowel.head;
			// Connect vowel and consonant linked list
			vowel.tail?.next = consonant.head;
			if (consonant.tail != null)
			{
				// When consonant node exists
				// Set new tail node of resultant linked list
				this.tail = consonant.tail;
			}
			else
			{
				// When consonant nodes not exists
				this.tail = vowel.tail;
			}
		}
		else
		{
			// When vowels not exist
			this.head = consonant.head;
			this.tail = consonant.tail;
		}
	}
}
fun main(args: Array < String > ): Unit
{
	var sll: SingleLL = SingleLL();
	// Constructed linked list
	sll.addNode('R');
	sll.addNode('E');
	sll.addNode('G');
	sll.addNode('U');
	sll.addNode('L');
	sll.addNode('A');
	sll.addNode('T');
	sll.addNode('I');
	sll.addNode('O');
	sll.addNode('N');
	print(" Before Arrange \n");
	// R → E → G → U → L → A → T → I → O → N → NULL
	sll.display();
	sll.arrangeNodes();
	print(" After Arrange \n");
	// E → U → A → I → O → R → G → L → T → N → NULL
	sll.display();
}

Output

 Before Arrange
 R → E → G → U → L → A → T → I → O → N → NULL
 After Arrange
 E → U → A → I → O → R → G → L → T → N → NULL

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved