Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. bool swap(wchar_t* string1, wchar_t* string2)
  2. {
  3.     size_t s1 = wcslen(string1);
  4.     size_t s2 = wcslen(string2);
  5.  
  6.     if (s1 == 0 && s2 == 0) //dva kratke neni nutne prehazovat
  7.         return false;
  8.     if (s2 == 0)
  9.         return true;
  10.     else if (s1 == 0)
  11.         return false;
  12.  
  13.     size_t i1 = 0, i2 = 0;
  14.     wchar_t l1 = string1[0];
  15.     wchar_t l2 = string2[0];
  16.     wchar_t c1, c2;
  17.  
  18.     while(i1 < s1 && i2 < s2)
  19.     {
  20.         c1 = i1 < s1 ? string1[i1] : ' ';
  21.         c2 = i2 < s2 ? string2[i2] : ' ';
  22.  
  23.         if (i1 < s1 && iswspace(l1) && iswspace(c1))
  24.         {
  25.             i1++;
  26.             continue;
  27.         }
  28.        
  29.         if (i2 < s2 && iswspace(l2) && iswspace(c2))
  30.         {
  31.             i2++;
  32.             continue;
  33.         }
  34.  
  35.         if (table[c1] > table[c2])
  36.             return true;
  37.  
  38.         i1++;
  39.         i2++;
  40.  
  41.         l1 = c1;
  42.         l2 = c2;
  43.     }
  44.  
  45.     l1 = string1[0];
  46.     l2 = string2[0];
  47.     while(i1 < s1 && i2 < s2)
  48.     {
  49.         c1 = i1 < s1 ? string1[i1] : ' ';
  50.         c2 = i2 < s2 ? string2[i2] : ' ';
  51.  
  52.         if (i1 < s1 && iswspace(l1) && iswspace(c1))
  53.         {
  54.             i1++;
  55.             continue;
  56.         }
  57.        
  58.         if (i2 < s2 && iswspace(l2) && iswspace(c2))
  59.         {
  60.             i2++;
  61.             continue;
  62.         }
  63.  
  64.         if (table2[c1] > table2[c2])
  65.             return true;
  66.  
  67.         i1++;
  68.         i2++;
  69.  
  70.         l1 = c1;
  71.         l2 = c2;
  72.     }
  73.  
  74.     return false;
  75. }
Add Comment
Please, Sign In to add comment