Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sort.h"
- #include <stdio.h>
- void sort(queue* q, int* count)
- {
- while((*count) < size(q)) {
- (*count) = 0;
- sort_insert(q, count, size(q) - 3);
- }
- }
- void sort_insert(queue* q, int* count, int k)
- {
- (*count)++;
- if (*count <= size(q) + k)
- {
- data_type v1=pop_front(q);
- data_type v2=pop_front(q);
- //printf("the first \t %d the second %d \n", v1.key,v2.key);
- if (v1.key > v2.key)
- {
- //printf("***3 %d\n", *count);
- insert(q,v1);
- //printf("***4 %d\n", *count);
- insert(q,v2);
- //print(q);
- //printf("5");
- }
- else
- {
- insert(q,v2);
- //printf("****6 %d\n", *count);
- // print(q);
- sort_insert(q,count, k);
- //printf("*****7 %d\n",*count);
- data_type v=pop_front(q);
- //print(q);
- if (v.key>v1.key)
- {
- insert(q,v);
- insert(q,v1);
- }
- else if (v.key < v1.key)
- {
- insert(q,v1);
- insert(q,v);
- }
- if (v.key == v1.key)
- {
- if (v.value>v1.value)
- {
- insert(q,v);
- insert(q,v1);
- }
- else {
- insert(q,v1);
- insert(q,v);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement