Advertisement
khAldr0g0

Shift Vowels DataStructure

Dec 16th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. // To shift the vowels at the front.
  2. // Non-Chronological order.
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. struct Node{
  7.     char ch;
  8.     struct Node *next;
  9. };
  10.  
  11. typedef struct Node N;
  12. N *start=NULL;
  13.  
  14.  
  15.  
  16. void insert(char c,N *node){
  17.     N *q;
  18.     node->ch=c;
  19.     if(start==NULL){
  20.         node->next=start;
  21.         start=node;
  22.         }
  23.     else{
  24.         q=start;
  25.         while(q->next != NULL){
  26.             q=q->next;
  27.             }
  28.         node->next=q->next;
  29.         q->next=node;
  30.         }
  31.     }
  32.  
  33. void display(N *node){
  34.     node=start;
  35.     while(node!=NULL){
  36.     printf("%c",node->ch);
  37.     node=node->next;
  38.     }
  39. }
  40.  
  41. int isVowel(char v){
  42.     if(v=='a' || v=='e' || v=='i' || v=='o' || v=='u')
  43.         return 1;
  44.     else if (v=='A' || v=='E' || v=='I' || v=='O' || v=='U')
  45.         return 1;
  46.     else
  47.         return 0;
  48. }
  49. // if the first node has a vowel, it satisfies the condition, so no need to swap
  50. // otherwise obtain the present vowel in temporary variable t, and then obtain the consonant
  51. // that has to reside at the position next to which the last vowel was encountered
  52. // and swap the values
  53. void arrangeVC(N *n){
  54.     char t;
  55.     N *q=malloc(sizeof(N));
  56.     q=n=start;
  57.     while(n!=NULL){
  58.         if(isVowel(n->ch) && n!=start){
  59.             t=n->ch;
  60.             q=q->next;
  61.             n->ch=q->ch;
  62.             q->ch=t;
  63.         }
  64.     n=n->next;
  65.     }
  66. display(n);
  67. }
  68.  
  69.  
  70.  
  71. int main(){
  72.  
  73. char ar[8]={'a','k','r','s','e','t','i','o'};
  74. int i;
  75. N *node;
  76. for(i=0; i<8; i++){
  77.     node=malloc(sizeof(N));
  78. insert(ar[i],node);
  79. }
  80.  
  81. display(node);
  82. printf("\n");
  83. arrangeVC(node);
  84.  
  85. char c=getchar();
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement