Thread: Alphabetical sorter

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    2

    Lightbulb Alphabetical order

    hello all, i am learning c++ i am new so i can not solve this problem completely. As you know problem is Alphabetical sorter but without vowel letter. I can do it with all letter but i need do it ignore vowel letter. Also The other characters of s follow the lower-case consonants so that their mutual order is not changed.

    Ex. The string ebddfff23E is transformed into the string bddfffe23E.

    What do you suggest me?

    Code:
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    
    using namespace std;
    
    void Show(char array[], int size)
    {  
        for (int i = 0; i < size; i++)
            std::cout << array[i];
        cout << endl;
    }    
     
    void BSort(char array[], int size)
    {
        for (int i = 0; i < size-1; i++)
        {
            if (array[i] > array[i+1])
            {            
                char temp = array[i+1];
                array[i+1] = array[i];
                array[i] = temp;
                
                i = -1;
            }
        }
    }
    
    
    int main(int argc, char *argv[])
    {    
        string s;
        cin>>s;
        int n  = s.size();
        
        char mychars[n] ;
     for (int i = 0; i < n; i++){
          mychars[i] = s.at(i);
          
          }
      
       int size = sizeof(mychars)/sizeof(char);
        Show(mychars, size);
        BSort(mychars, size);
        Show(mychars, size);
     
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Last edited by GSISONYA; 05-14-2015 at 04:20 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Ex. The string ebddfff23E is transformed into the string beeddfffe23E.
    > What do you suggest me?
    I suggest you explain where the two extra 'e' characters come from.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    2
    Quote Originally Posted by Salem View Post
    > Ex. The string ebddfff23E is transformed into the string beeddfffe23E.
    > What do you suggest me?
    I suggest you explain where the two extra 'e' characters come from.
    ops, sorry. it was mistake.

    it should be bddfffe23E

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Alphabetical sorting, etc Help
    By Lucifix in forum C Programming
    Replies: 5
    Last Post: 05-17-2010, 01:29 AM
  2. Can't Find Bug in basic MP3 Sorter
    By trickeastcs in forum C++ Programming
    Replies: 12
    Last Post: 12-14-2007, 05:31 PM
  3. Alphabetical orders using string
    By EdwardElric in forum C Programming
    Replies: 5
    Last Post: 10-01-2007, 01:17 AM
  4. Alphabetical order
    By BubbleMan in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2001, 03:38 PM
  5. Alphabetical Sort
    By steve8820 in forum C Programming
    Replies: 2
    Last Post: 09-28-2001, 07:10 AM