ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
   
 
Categories  >>  Software  >>  Operating Systems  >>  Data Structures
 
 
 
Question
Write programs for Bubble Sort, Quick sort
 Question Asked At :: Cognizent, Heap Sort
 Question Submitted By :: guest
I also faced this Question!!     Rank Answer Posted By  
 
Answer
/* Write C programs that implement the following sorting 
methods to sort
   a given list of integers in ascending order: i) Bubble 
sort */

#include <stdio.h>
#define MAX 10

void swapList(int *m,int *n)
{
   int temp;
   temp = *m;
   *m = *n;
   *n = temp;
}

// Function for Bubble Sort
void bub_sort(int list[], int n)
{
   int i,j;
   for(i=0;i<(n-1);i++)
      for(j=0;j<(n-(i+1));j++)
	     if(list[j] > list[j+1])
		    swapList(&list[j],&list[j+1]);
}

void readlist(int list[],int n)
{
   int j;
   printf("\nEnter the elements: \n");
   for(j=0;j<n;j++)
       scanf("%d",&list[j]);
}

// Showing the contents of the list
void printlist(int list[],int n)
{
   int j;
   for(j=0;j<n;j++)
      printf("%d\t",list[j]);
}

void main()
{
   int list[MAX], num;
   clrscr();
   printf("\n\n\n***** Enter the number of elements 
[Maximum 10] *****\n");
   scanf("%d",&num);
   readlist(list,num);
   printf("\n\nElements in the list before sorting are:\n");
   printlist(list,num);
   bub_sort(list,num);
   printf("\n\nElements in the list after sorting are:\n");
   printlist(list,num);
   getch();
}

 
Rakesh
 
View All Answers
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2012  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com