Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Arrange Consonants and Vowels #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions Arrange Consonants and Vowels
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// { Driver Code Starts
#include<bits/stdc++.h>
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<char> 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;
}