Advertisement
Guest User

lab26_sort

a guest
May 29th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include "sort.h"
  2. #include <stdio.h>
  3.  
  4. void sort(queue* q, int* count)
  5. {
  6. while((*count) < size(q)) {
  7. (*count) = 0;
  8. sort_insert(q, count, size(q) - 3);
  9. }
  10. }
  11.  
  12. void sort_insert(queue* q, int* count, int k)
  13. {
  14. (*count)++;
  15. if (*count <= size(q) + k)
  16. {
  17. data_type v1=pop_front(q);
  18. data_type v2=pop_front(q);
  19. //printf("the first \t %d the second %d \n", v1.key,v2.key);
  20. if (v1.key > v2.key)
  21. {
  22.  
  23. //printf("***3 %d\n", *count);
  24. insert(q,v1);
  25. //printf("***4 %d\n", *count);
  26. insert(q,v2);
  27. //print(q);
  28. //printf("5");
  29. }
  30. else
  31. {
  32. insert(q,v2);
  33. //printf("****6 %d\n", *count);
  34. // print(q);
  35. sort_insert(q,count, k);
  36. //printf("*****7 %d\n",*count);
  37. data_type v=pop_front(q);
  38. //print(q);
  39. if (v.key>v1.key)
  40. {
  41. insert(q,v);
  42. insert(q,v1);
  43. }
  44. else if (v.key < v1.key)
  45. {
  46. insert(q,v1);
  47. insert(q,v);
  48. }
  49. if (v.key == v1.key)
  50. {
  51. if (v.value>v1.value)
  52. {
  53. insert(q,v);
  54. insert(q,v1);
  55. }
  56. else {
  57. insert(q,v1);
  58. insert(q,v);
  59. }
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement