Advertisement
xlujiax

qsort_edit

Oct 18th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. /*
  10.  *
  11.  */
  12.  
  13. int comp(const void*, const void*);
  14.  
  15. int main(int argc, char** argv) {
  16.     char buff[500], *pal, *dBuff[50], **dic;
  17.     int n=0;
  18.    
  19.     while(gets(buff)){
  20.         pal = new char[strlen(buff)+1];
  21.         strcpy(pal, buff);
  22.         dBuff[n]=pal;
  23.         n++;        
  24.     }
  25.    
  26.     dic = new char*[n];
  27.     for (int i=0; i<n; i++)
  28.         dic[i]=dBuff[i];
  29.    
  30.     qsort(dic, n, sizeof(char**), comp);
  31.    
  32.     for (int i=0; i<n; i++)
  33.         cout<<dic[i]<<endl;
  34.     cout<<sizeof(dic);
  35.     return 0;
  36. }
  37.  
  38. int comp(const void*pt1, const void*pt2){
  39.     char**str1 = (char**)pt1;
  40.     char** str2 = (char**)pt2;
  41.     return -strcmp(*str1, *str2);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement