Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- private static void quick( int[] v, int inicio, int fim )
- {
- int aux, down, up, pivo;
- pivo = v[ inicio ];
- down = inicio;
- up = fim;
- while( down < up ){
- while( v[ down ] <= pivo && down < fim ) {
- down++;
- }
- while( v[ up ] > pivo && up > inicio ) {
- up--;
- }
- if( down < up ){
- aux = v[ down ];
- v[ down ] = v[ up ];
- v[ up ] = aux;
- }
- }
- v[ inicio ] = v[ up ];
- v[ up ] = pivo;
- if( inicio < up && inicio != up-1 ) {
- quick( v , inicio , up-1 );
- }
- if( fim > down && up+1 != fim ) {
- quick( v , up+1 , fim );
- }
- }
- public static void Main(string[] args)
- {
- Console.WriteLine("Início!");
- int[] vetor = new int[]{42,34,56,18,71,23,25,66,87};
- Console.WriteLine("\nVetor inicial:\n");
- for (int r = 0; r < vetor.Length; r++)
- {
- Console.Write("{0} ", vetor[r]);
- }
- quick( vetor , 0 , vetor.Length-1 );
- Console.WriteLine("\nVetor final:\n");
- for (int r = 0; r < vetor.Length; r++)
- {
- Console.Write("{0} ", vetor[r]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment