Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define NAME_MAX 25
- #define TEL_MAX 10
- typedef struct {
- char name[NAME_MAX], tel[TEL_MAX];
- int year, income;
- } Person;
- void swap(Person *a, Person *b) {
- Person aux = *a;
- *a = *b;
- *b = aux;
- }
- void QuickSort(Person v[], int l, int r)
- {
- if (l < r)
- {
- int mid = (l + r) / 2;
- swap(&v[l], &v[mid]);
- int i = l, j = r, d = 0;
- while (i < j)
- {
- if (strcmp(v[i].name, v[j].name) > 0 && v[i].year >= 30 && v[j].year >= 30)
- {
- swap(&v[i], &v[j]);
- d = 1 - d;
- }
- i += d;
- j -= 1 - d;
- }
- QuickSort(v, l, i - 1);
- QuickSort(v, i + 1, r);
- }
- }
- void displayPerson(const Person *const p) {
- printf("{%s %s %d %d}\n", p->name, p->tel, p->year, p->income);
- }
- int main(void) {
- Person p[] = {
- {"ion43", "089743", 31, 2},
- {"ion2", "089743", 1, 2},
- {"john1", "089743", 31, 2},
- {"ion4", "089743", 31, 2},
- {"ion0", "089743", 29, 2},
- {"a", "089744533", 38, 2},
- };
- QuickSort(p, 0, 5);
- for (int i = 0; i < 6; i++) {
- displayPerson(&p[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement