Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To shift the vowels at the front.
- // Non-Chronological order.
- #include <stdio.h>
- #include <stdlib.h>
- struct Node{
- char ch;
- struct Node *next;
- };
- typedef struct Node N;
- N *start=NULL;
- void insert(char c,N *node){
- N *q;
- node->ch=c;
- if(start==NULL){
- node->next=start;
- start=node;
- }
- else{
- q=start;
- while(q->next != NULL){
- q=q->next;
- }
- node->next=q->next;
- q->next=node;
- }
- }
- void display(N *node){
- node=start;
- while(node!=NULL){
- printf("%c",node->ch);
- node=node->next;
- }
- }
- int isVowel(char v){
- if(v=='a' || v=='e' || v=='i' || v=='o' || v=='u')
- return 1;
- else if (v=='A' || v=='E' || v=='I' || v=='O' || v=='U')
- return 1;
- else
- return 0;
- }
- // if the first node has a vowel, it satisfies the condition, so no need to swap
- // otherwise obtain the present vowel in temporary variable t, and then obtain the consonant
- // that has to reside at the position next to which the last vowel was encountered
- // and swap the values
- void arrangeVC(N *n){
- char t;
- N *q=malloc(sizeof(N));
- q=n=start;
- while(n!=NULL){
- if(isVowel(n->ch) && n!=start){
- t=n->ch;
- q=q->next;
- n->ch=q->ch;
- q->ch=t;
- }
- n=n->next;
- }
- display(n);
- }
- int main(){
- char ar[8]={'a','k','r','s','e','t','i','o'};
- int i;
- N *node;
- for(i=0; i<8; i++){
- node=malloc(sizeof(N));
- insert(ar[i],node);
- }
- display(node);
- printf("\n");
- arrangeVC(node);
- char c=getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement