Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SwapShake(SubTerra* Sub, int i){
- SubTerra Aux;
- strcpy(Aux.nome, Sub[i].nome);
- Aux.dens = Sub[i].dens;
- Aux.visao = Sub[i].visao;
- strcpy(Sub[i].nome, Sub[i-1].nome);
- Sub[i].dens = Sub[i-1].dens;
- Sub[i].visao = Sub[i-1].visao;
- strcpy(Sub[i-1].nome, Aux.nome);
- Sub[i-1].dens = Aux.dens;
- Sub[i-1].visao = Aux.visao;
- }
- void ShakeSort(SubTerra *Sub, int tam){
- int bottom = 0;
- int top = tam - 1;
- int swapped = 0;
- int ret;
- while(swapped == 0 && bottom < top){
- swapped = 1;
- for(int i = bottom; i<top; i++){
- ret = strcmp(Sub[i].nome, Sub[i+1].nome);
- if(ret > 0){
- SwapBubble(Sub, i);
- swapped = 0;
- }else if(ret == 0){
- if(Sub[i].dens > Sub[i+1].dens){
- SwapBubble(Sub, i);
- swapped = 0;
- }else if(Sub[i].dens == Sub[i+1].dens){
- if(Sub[i].visao > Sub[i+1].visao){
- SwapBubble(Sub, i);
- swapped = 0;
- }
- }
- }
- }
- --top;
- for(int i=top; i>bottom; i--){
- ret = strcmp(Sub[i].nome, Sub[i-1].nome);
- if(ret < 0){
- SwapShake(Sub, i);
- swapped = 0;
- }else if(ret == 0){
- if(Sub[i].dens < Sub[i-1].dens){
- SwapShake(Sub, i);
- swapped = 0;
- }else if(Sub[i].dens == Sub[i-1].dens){
- if(Sub[i].visao < Sub[i-1].visao){
- SwapShake(Sub, i);
- swapped = 0;
- }
- }
- }
- }
- ++bottom;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement