Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define M 3
  5.  
  6. typedef struct dane
  7. {
  8.     int ID;
  9.     struct osoba
  10.     {
  11.         char Imie[10];
  12.         char Nazwisko[10];
  13.     }osoba;
  14. }dane;
  15.  
  16.  
  17. void sort_tab(cons void *d, int mm)
  18. {
  19.     const dane *t = d;
  20.  
  21.     int i,j,min_index;
  22.     dane *temp = malloc(sizeof(dane));
  23.  
  24.     for(i=0; i<mm; i++)
  25.     {
  26.         min_index = i;
  27.         for(j=i+1; j<mm; j++)
  28.         {
  29.             if( strcmp((t+j)->osoba->Imie,(t+min_index)->osoba->Nazwisko) < 0 )
  30.             {
  31.                 min_index = j;
  32.             }
  33.         }
  34.  
  35.         if(min_index != i)
  36.         {
  37.             temp = (t+i);
  38.             (t+i) = (t+min_index);
  39.             (t+min_index) = temp;
  40.         }
  41.     }
  42.     return;
  43. }
  44.  
  45.  
  46. int main()
  47. {
  48.     dane tab[M];
  49.    
  50.     tab[0].ID = 1;
  51.     tab[0].osoba.Imie = "Ania";
  52.     tab[0].osoba.Nazwisko= "Kot";
  53.     tab[1].ID = 2;
  54.     tab[1].osoba.Imie = "Ania";
  55.     tab[1].osoba.Nazwisko= "Pies";
  56.     tab[2].ID = 3;
  57.     tab[2].osoba.Imie = "Ania";
  58.     tab[2].osoba.Nazwisko= "Kruk";
  59.  
  60.     sort_tab(&tab, M);
  61.    
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement