Jump to content
Fórum Script Brasil

Question

GALERA PRECISO IMPLEMENTAR O MALDITO DO QUICKSORT E INSERTSORT,TENTEI COLOCAR ALGUNS MÉTODOS MAS NÃO CONSEGUI... FIZ ISSO ATÉ AGORA.

 

 

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define t 8
 
int main () {
 
 int v[t],x = 0,y = 0,aux = 0,min =0,op,p=0,r=0;      
  
 for( x = 0; x < t; x++ ) 
 {
   printf("Entre com um inteiro para vetor[%d]: ",x);
   scanf("%d",&aux);
   v[x] = aux;
 }
 printf("Escolha uma opcao: ");
 printf("\n\nBubble Sort : 1\n");
 printf("\n\nSelect Sort : 2\n");
 printf("\n\nQuick Sort  : 3\n");
  printf("\n\nInsert Sort  : 4\n");
   
 scanf("%d",&op); 
 
 switch(op){
  case 1://BubbleSort
 
  for( x = 0; x < t; x++ )
  {
    for( y = x + 1; y < t; y++ ) 
    {
      if ( v[x] > v[y] )
      {
         aux = v[x];
         v[x] = v[y];
         v[y] = aux;
    }
   }
}
   printf("\n Elementos ordenados:");
 
for( x = 0; x < 8; x++ )
{
 
  printf("\n %d",v[x]); // exibe o vetor ordenado
break;
case 2: //SelectSort
 
   for (x = 0; x < t; x++) 
   {
     min = x;
for (y = (x+1); y < t; y++) {
       if(v[y] < v[min]) 
         min = y;
     }
     if (x != min) {
       aux = v[x];
       v[x] = v[min];
       v[min] = aux;
     }
  }
  printf("\n Elementos ordenados:");
 
for( x = 0; x < 8; x++ )
{
 
  printf("\n %d",v[x]); // exibe o vetor ordenado
}
break;
case 3:
    
 
break;
case 4:
    
 
break;
 
 
 
}
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...