Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int parent(int i);
- int left(int i);
- int right (int i);
- int *kopiec_wstaw(int *A, int key, int *heap_size);
- int main()
- {
- int *tablica = NULL;
- int heap_size = -1;
- tablica = kopiec_wstaw(tablica, 10, &heap_size);
- tablica = kopiec_wstaw(tablica, 20, &heap_size);
- printf("\n1. wstawiony element: %i", tablica[0]);
- printf("\n2. wstawiony element: %i", tablica[1]);
- getchar();
- return 0;
- }
- int parent(int i)
- {
- return (i-1)/2;
- }
- int left(int i)
- {
- return 2*i;
- }
- int right (int i)
- {
- return 2*i+1;
- }
- int *kopiec_wstaw(int *A, int key, int *heap_size)
- {
- int i;
- (*heap_size)++;
- A = (int *) realloc(A, (*heap_size+1)*sizeof(int));
- i= *heap_size;
- while (i>0 && A[parent(i)]<key)
- {
- printf("petla");
- A[i] = A[parent(i)];
- i = parent(i);
- }
- printf("\nkey: %i", key);
- A[i] = key;
- return A;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement