Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. void SwapShake(SubTerra* Sub, int i){
  2. SubTerra Aux;
  3. strcpy(Aux.nome, Sub[i].nome);
  4. Aux.dens = Sub[i].dens;
  5. Aux.visao = Sub[i].visao;
  6.  
  7. strcpy(Sub[i].nome, Sub[i-1].nome);
  8. Sub[i].dens = Sub[i-1].dens;
  9. Sub[i].visao = Sub[i-1].visao;
  10.  
  11. strcpy(Sub[i-1].nome, Aux.nome);
  12. Sub[i-1].dens = Aux.dens;
  13. Sub[i-1].visao = Aux.visao;
  14. }
  15.  
  16. void ShakeSort(SubTerra *Sub, int tam){
  17. int bottom = 0;
  18. int top = tam - 1;
  19. int swapped = 0;
  20. int ret;
  21.  
  22. while(swapped == 0 && bottom < top){
  23.  
  24. swapped = 1;
  25.  
  26. for(int i = bottom; i<top; i++){
  27.  
  28. ret = strcmp(Sub[i].nome, Sub[i+1].nome);
  29.  
  30. if(ret > 0){
  31. SwapBubble(Sub, i);
  32. swapped = 0;
  33. }else if(ret == 0){
  34. if(Sub[i].dens > Sub[i+1].dens){
  35. SwapBubble(Sub, i);
  36. swapped = 0;
  37. }else if(Sub[i].dens == Sub[i+1].dens){
  38. if(Sub[i].visao > Sub[i+1].visao){
  39. SwapBubble(Sub, i);
  40. swapped = 0;
  41. }
  42. }
  43. }
  44.  
  45. }
  46.  
  47. --top;
  48. for(int i=top; i>bottom; i--){
  49.  
  50. ret = strcmp(Sub[i].nome, Sub[i-1].nome);
  51.  
  52. if(ret < 0){
  53. SwapShake(Sub, i);
  54. swapped = 0;
  55. }else if(ret == 0){
  56. if(Sub[i].dens < Sub[i-1].dens){
  57. SwapShake(Sub, i);
  58. swapped = 0;
  59. }else if(Sub[i].dens == Sub[i-1].dens){
  60. if(Sub[i].visao < Sub[i-1].visao){
  61. SwapShake(Sub, i);
  62. swapped = 0;
  63. }
  64. }
  65. }
  66. }
  67. ++bottom;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement