Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- void swap(int *xp, int *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- void sort(int n, ...)
- {
- va_list argument; //declaram variabila de tip va_list
- int i, *elmAnt, *elmCurent;
- int sortat = 0;
- do{
- sortat = 1;
- va_start(argument, n); //apelam va_start() si o initializam
- elmAnt = va_arg(argument, int *);
- for (i = 0; i < n - 1; i++) {
- elmCurent = va_arg(argument, int *);
- if ((*elmAnt) > (*elmCurent)) {
- swap(elmAnt, elmCurent);
- sortat = 0;
- }
- elmAnt = elmCurent;
- }
- }while (sortat == 0);
- va_end(argument); // terminare parcurgere + eliberare memorie
- }
- int main(void){
- int a = 2, b = 1, c = 0;
- sort(3, &a, &b, &c);
- printf("%d %d %d", a, b, c);
- scanf("%*c");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement