Sunday, December 15, 2019

Quick Sort Program in C

A simple quick sort program that I wrote a long time ago using C programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.com

I am also a book author you can purchase my books on computer programming and information technology in the following links below.

https://www.mindshaperspublishing.com/
https://www.unlimitedbooksph.com/

If you like my video tutorials kindly click the like button and subscribe for more video tutorials on my channel.

Thank you very much for your help and support.
 
 
 
 
Sample Program Output
 

Program Listing 
 
quick.c
 
#include <stdio.h>
#include <conio.h>


#define maxsize 100

int A[maxsize];

void quicksort(int a, int b)
{
  int rtidx=0,ltidx=0,k=a,l=0,pivot;
  int leftarr[maxsize],rtarr[maxsize];
  pivot=A[a];
  if(a==b)return;
  while(k<b)
  {
    ++k;
     if(A[k]<A[a])
     {
      leftarr[ltidx]=A[k];
      ltidx++;
      }
        else
        {
        rtarr[rtidx]=A[k];
        rtidx++;
         }
          }

     k=a;
     for(l=0;l<ltidx;++l)A[k++]=leftarr[l];
     A[k++]=pivot;
     for(l=0;l<rtidx;++l)A[k++]=rtarr[l];
     if(ltidx>0)quicksort(a,a+ltidx-1);
     if(rtidx>0)quicksort(b-rtidx+1,b);
     }

void printarr(int a)
{
  int i;
  for(i=0;i<a;i++)
  {
  printf(" %d ",A[i]);
  }
  }

main()
{
  int i=0,s=0;
  clrscr();
  printf("\n======================================================");
  printf("\n\t QUICK SORT USING C VERSION 1.0");
  printf("\n Created By: Mr. Jake Rodriguez Pomperada, MAED-IT");
  printf("\n======================================================");
  printf("\n\n");
  printf("How many numbers to process :=> ");
  scanf("%d",&s);
  for(i=0;i<s;i++)
  {
     printf("Enter value No. %d :=> ",i+1);
     scanf("%d",&A[i]);
     }
  printf("\n==========================");
  printf("\n\t  RESULTS ");
  printf("\n==========================");
  printf("\n");
  printf("The Values before sorting ");
  printf("\n");
  printarr(s);
  quicksort(0,s-1);
  printf("\n\n");
  printf("The Values after sorting");
  printf("\n");
  printarr(s);
  getche();
  }
 

No comments:

Post a Comment