TP3 fini
This commit is contained in:
@@ -64,5 +64,29 @@ void hanoi_rec(stack *p1, stack *p2, stack *p3,
|
||||
}
|
||||
|
||||
void bubble_sort_stack(stack *p) {
|
||||
int n = size_stack(p);
|
||||
stack *p_aux = create_stack();
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < n - 1; j++) {
|
||||
push(pop(p), p_aux);
|
||||
}
|
||||
print_stacks(n - i, 2, p, p_aux);
|
||||
for (int j = i; j < n - 1; j++) {
|
||||
int a = pop(p);
|
||||
int b = pop(p_aux);
|
||||
if (a < b) {
|
||||
push(a, p);
|
||||
push(b, p);
|
||||
} else {
|
||||
push(b, p);
|
||||
push(a, p);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < i; j++) {
|
||||
push(pop(p_aux), p);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
delete_stack(p_aux);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user