From d8ab0342660bc801b9aebccd5227e4127c59d15f Mon Sep 17 00:00:00 2001 From: Udhay <72250606+Udhay-Brahmi@users.noreply.github.com> Date: Wed, 23 Dec 2020 07:58:04 +0530 Subject: [PATCH] Create Arrange Consonants and Vowels --- Arrange Consonants and Vowels | 110 ++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Arrange Consonants and Vowels diff --git a/Arrange Consonants and Vowels b/Arrange Consonants and Vowels new file mode 100644 index 0000000..1d9a982 --- /dev/null +++ b/Arrange Consonants and Vowels @@ -0,0 +1,110 @@ +// { Driver Code Starts +#include +using namespace std; + +struct Node +{ + char data; + struct Node *next; + + Node(int x){ + data = x; + next = NULL; + } + +}; + +void printlist(Node *head) +{ + if (head==NULL)return; + while (head != NULL) + { + cout << head->data << " "; + head = head->next; + } + cout << endl; +} + +void append(struct Node** headRef, char data) +{ + struct Node* new_node = new Node(data); + struct Node *last = *headRef; + + if (*headRef == NULL) + { + *headRef = new_node; + return; + } + while (last->next != NULL) + last = last->next; + last->next = new_node; + return; +} + +// task is to complete this function +struct Node* arrange(Node *head); + +int main() +{ + int T; + cin>>T; + while(T--){ + int n; + char tmp; + struct Node *head = NULL; + cin>>n; + while(n--){ + cin>>tmp; + append(&head, tmp); + } + head = arrange(head); + printlist(head); + } + return 0; +} + +// } Driver Code Ends + + +/* +Structure of the node of the linked list is as +struct Node +{ + char data; + struct Node *next; + + Node(int x){ + data = x; + next = NULL; + } + +}; +*/ +// task is to complete this function +// function should return head to the list after making +// necessary arrangements +struct Node* arrange(Node *temp) +{ + //Code here + vector vow,con; + Node *head =temp; + while(head!=NULL){ + if(head->data=='a' || head->data=='i' || head->data=='e'|| head->data=='o' || head->data == 'u'){ + vow.push_back(head->data); + } + else{ + con.push_back(head->data); + } + head=head->next; + } + Node* abc =temp; + for(auto e:vow){ + abc->data = e; + abc=abc->next; + } + for(auto e:con){ + abc->data=e; + abc=abc->next; + } + return temp; +}