{"id":4872,"date":"2021-09-13T02:55:06","date_gmt":"2021-09-13T02:55:06","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=4872"},"modified":"2022-11-14T10:53:07","modified_gmt":"2022-11-14T10:53:07","slug":"arrange-consonants-and-vowels-nodes-in-a-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/","title":{"rendered":"Arrange consonants and vowels nodes in a linked list"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\" alt=\"\" \/><\/p>\n<p>This blog will give an efficient approach to arrange vowels and consonants in linked list. Arranging vowels and consonants in linked list will definitely help for better understanding of data structures like linked lists. Let\u2019s discuss how to arrange vowels and consonants in linked list in detail.<\/p>\n<h2>How To Arrange Vowels And Consonants In Linked List<\/h2>\n<p>In this problem, we will be given a linked list in which each node will have an alphabet character as data, and we need to rearrange the nodes of the linked list so that all nodes having vowel data appear before the consonant ones. <\/p>\n<p><strong>Note:<\/strong>We are not allowed to disturb the relative order of vowels and consonants.<\/p>\n<p>Let the given input be:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/Arrange-consonants-and-vowels-nodes-in-a-linked-list-1.png\" alt=\"\" \/><\/p>\n<p>The output should be:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/Arrange-consonants-and-vowels-nodes-in-a-linked-list-2.png\" alt=\"\" \/><\/p>\n<p><strong>Let\u2019s first understand the problem statement with the help of examples.<\/strong><\/p>\n<p>If the given linked list is c\u2192a\u2192l\u2192e\u2192p\u2192o\u2192w:<\/p>\n<ul>\n<li>Then, according to the problem statement, we need to rearrange the node of the linked list such that all the vowel nodes come before the consonant nodes. Also, we need to make sure that the order of occurrence of nodes within vowel nodes and consonant nodes after rearrangement should be the same as their order of occurrence in the original list.<\/li>\n<li>The output linked list after rearrangement of nodes will be a\u2192e\u2192o\u2192c\u2192l\u2192p\u2192w.<\/li>\n<li>In the output linked list, we can see that all the vowel nodes a, e, o are before the consonant nodes c, l, p and w. Also, if we notice carefully, we can observe that within vowel nodes and consonant nodes the order of occurrences of nodes is the same as their order of occurrence in the input list.\n<ul>\n<li>The order of occurrence of vowel nodes in the input list is a, e, o and similarly in our output list, the order of occurrence of vowel nodes is the same a, e, o.<\/li>\n<li>The order of occurrence of consonant nodes in the input list is c, l, p, w and similarly in our output list the order of occurrence of consonant nodes is the same c, l, p, w.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Let\u2019s take another example, say if the input list is: a\u2192b\u2192c\u2192d\u2192e\u2192o\u2192i\u2192u<\/p>\n<ul>\n<li>In this case, our output singly linked list after rearrangement will be: a\u2192e\u2192o\u2192i\u2192u\u2192b\u2192c\u2192d<\/li>\n<\/ul>\n<p>Now, I think the problem statement is clear, so let&#8217;s see how we can approach it. Any ideas? <\/p>\n<ul>\n<li>The naive approach would be to create 2 vectors that would be storing the address of nodes. While traversing the list, insert vowel nodes in the first vector and consonant ones in the second one. Finally, create a new linked list, keeping all vowel nodes before consonant nodes.<\/li>\n<\/ul>\n<p>The above approach will have a linear space and time complexity. But can we do better than this? Yes, we can improve the space complexity of our code to constant space.<\/p>\n<ul>\n<li>So, our idea will be to traverse the list and find the first vowel node. This will be the new head of our modified list. Now, we would bring this node at the beginning of the list and make this head of our modified list. We would store the previous vowel node\u2019s address, and when we encounter another vowel node in the future, we would remove it from there and place it after this node. We will repeat this process till we traverse the whole list completely.<\/li>\n<\/ul>\n<p>Let\u2019s move to the next section to see this process in more depth.<\/p>\n<h2>Approach and Algorithm To Arrange Vowels And Consonants In Linked List<\/h2>\n<ol>\n<li>Find the first vowel node and make it head of the list, i.e., bring it before the old head of the list.<\/li>\n<li>Now store the position of the previous vowel node.<\/li>\n<li>Traverse the list, and when we encounter a vowel node,\n<ul>\n<li>We would remove it from its place.<\/li>\n<li>Insert it after the previous vowel node.<\/li>\n<li>Update the previous vowel variable to this node.<\/li>\n<li>Connect it with the remaining list.<\/li>\n<\/ul>\n<\/li>\n<li>At last, the consonants would automatically come after vowels and the order of occurrence of each vowel and consonant would be preserved.<\/li>\n<\/ol>\n<h3>Dry Run To Arrange Vowels And Consonants In Linked List<\/h3>\n<p><strong>For better understanding follow dry run along with code<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/Arrange-consonants-and-vowels-nodes-in-a-linked-list-3.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/Arrange-consonants-and-vowels-nodes-in-a-linked-list-4.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/Arrange-consonants-and-vowels-nodes-in-a-linked-list-5.png\" alt=\"\" \/><\/p>\n<h2>Code Implementation To Arrange Vowels And Consonants In Linked List<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_4873 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_4873 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_4873 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_4873 .wpsm_nav-tabs > li.active > a, #tab_container_4873 .wpsm_nav-tabs > li.active > a:hover, #tab_container_4873 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_4873 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_4873 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_4873 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_4873 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_4873 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_4873 .wpsm_nav-tabs > li > a:hover , #tab_container_4873 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_4873 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_4873 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_4873 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_4873 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_4873 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_4873 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_4873 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4873 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_4873 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4873 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_4873 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_4873\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_4873\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_4873_1\" aria-controls=\"tabs_desc_4873_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_4873_2\" aria-controls=\"tabs_desc_4873_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_4873_3\" aria-controls=\"tabs_desc_4873_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_4873_4\" aria-controls=\"tabs_desc_4873_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_4873\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_4873_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<bits\/stdc++.h>\r\nusing namespace std;\r\nclass Node\r\n{\r\n    public:\r\n    char data;\r\n    Node* next;\r\n    Node(char x){\r\n        data = x;\r\n   next = NULL;\r\n    }\r\n};\r\n \r\nvoid printlist(Node *head){\r\n        while (head != NULL) {\r\n            cout<<(head->data)<<\" ,\";\r\n            head = head->next;\r\n        }\r\n        cout<<'&#92;n';\r\n    }\r\n \r\nbool isVowel(char x)\r\n{\r\n    if(x == 'a' || x == 'e' || x == 'i' ||x == 'o' || x == 'u')\r\n          return true;\r\n \r\n    return false;\r\n}\r\n \r\nNode *arrange(Node *head)\r\n{\r\n    Node *newHead = head;\r\n \r\n    \/\/ to keep track of previously encountered vowel\r\n    Node *prevVowel;\r\n \r\n    Node *curr = head;\r\n \r\n    \/\/ empty list\r\n    if (head == NULL)\r\n        return NULL;\r\n \r\n    \/\/To find first vowel node, run a loop separately\r\n    \/\/as this would be head of our newly created list\r\n    if (isVowel(head->data))\r\n              prevVowel = head;\r\n \r\n    else\r\n    {\r\n \r\n         while (curr->next != NULL &&!isVowel(curr->next->data))\r\n                       curr = curr->next;\r\n \r\n \r\n        \/\/when there are only consonants in the list.\r\n        if (curr->next == NULL)\r\n            return head;\r\n \r\n        \/\/found the head of new list so update prevVowel, remove\r\n        \/\/it form its place and make it head of new list\r\n        prevVowel = newHead = curr->next;\r\n        curr->next = curr->next->next;\r\n        prevVowel->next = head;\r\n    }\r\n \r\n    \/\/ Now traverse the list and perform the operations\r\n    \/\/ mentioned in step 3\r\n \r\n    while (curr != NULL && curr->next != NULL)\r\n    {\r\n        if (isVowel(curr->next->data))\r\n        {\r\n            \r\n            if (curr == prevVowel)\r\n            {\r\n                \/\/ if current node is just after prevVowel\r\n                prevVowel = curr = curr->next;\r\n            }\r\n            else\r\n            {\r\n \r\n                Node *temp = prevVowel->next;\r\n \r\n                \/\/ move current node after prevVowel\r\n                prevVowel->next = curr->next;\r\n \r\n                \/\/ update prevVowel\r\n                prevVowel = prevVowel->next;\r\n \r\n                curr->next = curr->next->next;\r\n \r\n                \/\/ re-attach the prevVowel with remaining list\r\n                prevVowel->next = temp;\r\n            }\r\n        }\r\n        else\r\n        {\r\n \r\n            \/\/ if no vowel is present then simply move to next\r\n            curr = curr->next;\r\n        }\r\n    }\r\n    return newHead;\r\n}\r\n \r\nint main()\r\n{\r\n    Node *head = new Node('c');\r\n    head->next = new Node('a');\r\n    head->next->next = new Node('l');\r\n    head->next->next->next = new Node('e');\r\n    head->next->next->next->next = new Node('p');\r\n    head->next->next->next->next->next = new Node('o');\r\n    head->next->next->next->next->next->next = new Node('w');\r\n    \r\n \r\n    printf(\"Input list:&#92;n\");\r\n    printlist(head);\r\n \r\n    head = arrange(head);\r\n \r\n    printf(\"Output list:&#92;n\");\r\n    printlist(head);\r\n \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_4873_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include<stdio.h>\r\n#include<stdlib.h>\r\n#include<stdbool.h>\r\n\/* A linked list node *\/\r\nstruct Node\r\n{\r\n    char data;\r\n    struct Node *next;\r\n};\r\n \r\n\/* Function to add new node to the List *\/\r\nstruct Node *newNode(char key)\r\n{\r\n    struct Node *temp = (struct Node*)malloc(sizeof(struct Node));\r\n    temp->data = key;\r\n    temp->next = NULL;\r\n    return temp;\r\n}\r\n \r\n\/\/ utility function to print linked list\r\nvoid printlist(struct Node *head)\r\n{\r\n    if (! head)\r\n    {\r\n        printf(\"Empty list &#92;n\");\r\n        return;\r\n    }\r\n    while (head != NULL)\r\n    {\r\n        printf(\"%c\",head->data);\r\n        if (head->next)\r\n        printf(\"->\");\r\n        head = head->next;\r\n    }\r\n    printf(\"&#92;n\");\r\n}\r\n \r\n\/\/ utility function for checking vowel\r\nbool isVowel(char x)\r\n{\r\n    return (x == 'a' || x == 'e' || x == 'i' ||\r\n            x == 'o' || x == 'u');\r\n}\r\n \r\n\/* function to arrange consonants and\r\nvowels nodes *\/\r\nstruct Node *arrange(struct Node *head)\r\n{\r\n    struct Node *newHead = head;\r\n \r\n    \/\/ for keep track of vowel\r\n    struct Node *latestVowel;\r\n \r\n    struct Node *curr = head;\r\n \r\n    \/\/ list is empty\r\n    if (head == NULL)\r\n        return NULL;\r\n    if (isVowel(head->data))\r\n        latestVowel = head;\r\n \r\n    else\r\n    {\r\n        while (curr->next != NULL &&\r\n            !isVowel(curr->next->data))\r\n            curr = curr->next;\r\n \r\n        if (curr->next == NULL)\r\n            return head;\r\n        latestVowel = newHead = curr->next;\r\n        curr->next = curr->next->next;\r\n        latestVowel->next = head;\r\n    }\r\n \r\n    while (curr != NULL && curr->next != NULL)\r\n    {\r\n        if (isVowel(curr->next->data))\r\n        {\r\n            if (curr == latestVowel)\r\n            {\r\n                latestVowel = curr = curr->next;\r\n            }\r\n            else\r\n            {\r\n                struct Node *temp = latestVowel->next;\r\n \r\n                latestVowel->next = curr->next;\r\n\r\n                latestVowel = latestVowel->next;\r\n \r\n                curr->next = curr->next->next;\r\n                latestVowel->next = temp;\r\n            }\r\n        }\r\n        else\r\n        {\r\n \r\n            curr = curr->next;\r\n        }\r\n    }\r\n    return newHead;\r\n}\r\n\r\nint main()\r\n{\r\n    struct Node *head = newNode('a');\r\n    head->next = newNode('b');\r\n    head->next->next = newNode('c');\r\n    head->next->next->next = newNode('e');\r\n    head->next->next->next->next = newNode('d');\r\n    head->next->next->next->next->next = newNode('o');\r\n    head->next->next->next->next->next->next = newNode('x');\r\n    head->next->next->next->next->next->next->next = newNode('i');\r\n \r\n    printf(\"Input list :&#92;n\");\r\n    printlist(head);\r\n \r\n    head = arrange(head);\r\n \r\n    printf(\"Output list :&#92;n\");\r\n    printlist(head);\r\n \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_4873_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node \r\n{\r\n    char data;\r\n    Node next;\r\n    Node(char x)\r\n    {\r\n        data=x;\r\n    }\r\n}\r\npublic class ArrangeVowels \r\n{\r\n    static void printList(Node head)\r\n    {\r\n        while(head!=null)\r\n        {\r\n            System.out.print(head.data+\" ,\");\r\n            head=head.next;\r\n        }\r\n        System.out.println();\r\n    }\r\n    static boolean isVowel(char x)\r\n    {\r\n        if(x== 'a' || x== 'e' || x=='i' || x=='o' || x=='u')\r\n        {\r\n            return true;\r\n        }\r\n        return false;\r\n    }\r\n    static Node arrange(Node head)\r\n    {\r\n        Node newHead=head;\r\n        Node prevVowel;\r\n        Node curr=head;\r\n\r\n        if(head==null)\r\n        {\r\n            return null;\r\n        }\r\n        if(isVowel(head.data))\r\n        {\r\n            prevVowel=head;\r\n        }\r\n        else{\r\n            while(curr.next!=null && !isVowel(curr.next.data))\r\n            {\r\n                curr=curr.next;\r\n            }\r\n            if(curr.next==null)\r\n            {\r\n                return head;\r\n            }\r\n            prevVowel=newHead=curr.next;\r\n            curr.next=curr.next.next;\r\n            prevVowel.next=head;\r\n        }\r\n        while(curr!=null && curr.next!=null)\r\n        {\r\n            if(isVowel(curr.next.data))\r\n            {\r\n                if(curr==prevVowel)\r\n                {\r\n                    prevVowel=curr=curr.next;\r\n                }\r\n                else{\r\n                    Node temp=prevVowel.next;\r\n                    prevVowel.next=curr.next;\r\n                    prevVowel=prevVowel.next;\r\n                    curr.next=curr.next.next;\r\n                    prevVowel.next=temp;\r\n                }\r\n            }\r\n            else\r\n            {\r\n                curr=curr.next;\r\n            }\r\n        }\r\n        return newHead;\r\n    }\r\n    public static void main(String[] args) \r\n    {\r\n        Node head=new Node('c');\r\n        head.next = new Node('a');\r\n        head.next.next = new Node('l');\r\n        head.next.next.next = new Node('e');\r\n        head.next.next.next.next = new Node('p');\r\n        head.next.next.next.next.next= new Node('o');\r\n        head.next.next.next.next.next.next= new Node('w');\r\n\r\n        System.out.println(\"Input List\");\r\n        printList(head);\r\n        head=arrange(head);\r\n\r\n        System.out.println(\"Output List\");\r\n        printList(head);\r\n        \r\n\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_4873_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Node:\r\n\tdef __init__(self, x):\r\n\t\tself.data = x\r\n\t\tself.next = None\r\n\r\ndef printlist(head):\r\n\r\n\twhile (head != None):\r\n\t\tprint(head.data, end = \", \")\r\n\t\thead = head.next\r\n\tprint()\r\n\r\ndef isVowel(x):\r\n\treturn (x == 'a' or x == 'e' or x == 'i'\r\n\t\t\tor x == 'o' or x == 'u' or x == 'A'\r\n\t\t\tor x == 'E' or x == 'I' or x == 'O'\r\n\t\t\tor x == 'U')\r\n\r\ndef arrange(head):\r\n\tnewHead = head\r\n\r\n\tlatestVowel = None\r\n\r\n\tcurr = head\r\n\r\n\tif (head == None):\r\n\t\treturn None\r\n\r\n\tif (isVowel(head.data)):\r\n\r\n\t\tlatestVowel = head\r\n\r\n\telse:\r\n\r\n\t\twhile (curr.next != None and\r\n\t\t\tnot isVowel(curr.next.data)):\r\n\t\t\tcurr = curr.next\r\n\r\n\r\n\t\tif (curr.next == None):\r\n\t\t\treturn head\r\n\r\n\t\tlatestVowel = newHead = curr.next\r\n\t\tcurr.next = curr.next.next\r\n\t\tlatestVowel.next = head\r\n\r\n\twhile (curr != None and curr.next != None):\r\n\t\tif (isVowel(curr.next.data)):\r\n\t\t\t\r\n\t\t\tif (curr == latestVowel):\r\n\r\n\t\t\t\tlatestVowel = curr = curr.next\r\n\r\n\t\t\telse:\r\n\r\n\t\t\t\ttemp = latestVowel.next\r\n\t\t\t\tlatestVowel.next = curr.next\r\n\t\t\t\tlatestVowel = latestVowel.next\r\n\t\t\t\tcurr.next = curr.next.next\r\n\t\t\t\tlatestVowel.next = temp\r\n\r\n\t\telse:\r\n\r\n\t\t\tcurr = curr.next\r\n\r\n\treturn newHead\r\n\r\nif __name__ == '__main__':\r\n\t\r\n\thead = Node('c')\r\n\thead.next = Node('a')\r\n\thead.next.next = Node('l')\r\n\thead.next.next.next = Node('e')\r\n\thead.next.next.next.next = Node('p')\r\n\thead.next.next.next.next.next = Node('o')\r\n\thead.next.next.next.next.next.next = Node('w')\r\n\r\n\tprint(\"Input list:\")\r\n\tprintlist(head)\r\n\r\n\thead = arrange(head)\r\n\r\n\tprint(\"Output list :\")\r\n\tprintlist(head)\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_4873 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_4873 a\"),jQuery(\"#tab-content_4873\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<p><strong>Output<\/strong><\/p>\n<p><strong>Input list:<\/strong><br \/>\nc, a, l, e, p, o, w,<br \/><strong>Output list:<\/strong><br \/>\na, e, o, c, l, p, w,<\/p>\n<p><strong>Time Complexity To Arrange Vowels And Consonants In Linked List:<\/strong> O(n)<\/p>\n<p>Hopefully, this blog will give understanding for solving the most efficient approach to arrange vowels and consonants in linked list. Linked list is a topic which is needed to understand the concept of data structure that will help in clearing the interview of tech companies. If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, you can follow this link <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n<p>## FAQs<\/p>\n<p>**1. What is the order of a linked list?**<br \/>\nA linked list is a sequence of nodes that contain two fields: an integer value and a link to the next node. The last node is linked to a terminator used to signify the end of the list.<\/p>\n<p>**2. Why Do We Use Linked Lists?**<br \/>\nLinked lists are often used because of their efficient insertion and deletion. They can be used to implement stacks, queues, and other abstract data types.<\/p>\n<p>**3. Why is insertion faster in the linked list?**<br \/>\nOnce you arrive at the ith node, inserting\/deleting only takes O(1) time since it&#8217;s just a rearrangement of pointers, no shifting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog will give an efficient approach to arrange vowels and consonants in linked list. Arranging vowels and consonants in linked list will definitely help for better understanding of data structures like linked lists. Let\u2019s discuss how to arrange vowels and consonants in linked list in detail. How To Arrange Vowels And Consonants In Linked [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-4872","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes<\/title>\n<meta name=\"description\" content=\"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-13T02:55:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-14T10:53:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Arrange consonants and vowels nodes in a linked list\",\"datePublished\":\"2021-09-13T02:55:06+00:00\",\"dateModified\":\"2022-11-14T10:53:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\"},\"wordCount\":949,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\",\"name\":\"Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\",\"datePublished\":\"2021-09-13T02:55:06+00:00\",\"dateModified\":\"2022-11-14T10:53:07+00:00\",\"description\":\"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Arrange consonants and vowels nodes in a linked list\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes","description":"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes","og_description":"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.","og_url":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-09-13T02:55:06+00:00","article_modified_time":"2022-11-14T10:53:07+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Arrange consonants and vowels nodes in a linked list","datePublished":"2021-09-13T02:55:06+00:00","dateModified":"2022-11-14T10:53:07+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/"},"wordCount":949,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/","name":"Linked List | Arrange consonants and vowels nodes in a linked list | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png","datePublished":"2021-09-13T02:55:06+00:00","dateModified":"2022-11-14T10:53:07+00:00","description":"Learn how to arrange consonant and vowel nodes in a linked list. This blog explains how you can arrange consonants and vowels nodes in a linked list in the most optimal way.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645000301954-Article_128.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/arrange-consonants-and-vowels-nodes-in-a-linked-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Arrange consonants and vowels nodes in a linked list"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=4872"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4872\/revisions"}],"predecessor-version":[{"id":10467,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4872\/revisions\/10467"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=4872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=4872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=4872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}