Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6.  
  7.      void Wpisz(int iloscslow,string tab[],string *wskaznik[])
  8.     {
  9.        
  10.      cout<<"podaj kolejne slowa:\n";
  11.  
  12.         for(int i=0;i<40;i++)
  13.         {
  14.  
  15.         getline(cin,tab[i]);
  16.  
  17.         wskaznik[i]=&tab[i];
  18.  
  19.  
  20.     if((*wskaznik[i]).empty())
  21.             {
  22.                 iloscslow=i+1;
  23.                 break;
  24.             }
  25.         }
  26.  
  27.  
  28.     }
  29.  
  30.    void SortujAlfabetycznie(int iloscslow, string *wskaznik[])
  31.    {
  32.        for(int i=0;i<iloscslow;i++)
  33.     {
  34.  
  35.         for(int j=0;j<iloscslow-1;j++)
  36.         {
  37.  
  38.             if(*wskaznik[j] > *wskaznik[j+1])
  39.                 {
  40.                     swap(*wskaznik[j],*wskaznik[j+1]);
  41.                 }
  42.         }
  43.  
  44.     }
  45.    }
  46.  
  47.  
  48.     void Wypisz(string *wskaznik[], int iloscslow)
  49.     {
  50.         cout<<"Te slowa w kolejnosci alfabetycznej to: \n";
  51.  
  52.     for(int i=0;i<iloscslow;i++)
  53.         {
  54.             cout<<*wskaznik[i]<<endl;
  55.         }
  56.     }
  57.  
  58. int main()
  59. {
  60.     string tab[40];
  61.     string *wskaznik[40];
  62.     int iloscslow=0;
  63.  
  64. Wpisz(iloscslow, tab,wskaznik);
  65. SortujAlfabetycznie( iloscslow,wskaznik);
  66. Wypisz(wskaznik,iloscslow);
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement