Write programs for Bubble Sort, Quick sort

Answer Posted / cynthia

//Program for implementing Bubble Sort

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,p,t;
clrscr();
printf("Enter the array limit");
scanf("%d",&n);
printf("\nEnter %d elemts",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
p=0;
while(p<n-i)
{
if(a[p]>a[p+1])
{
t=a[p];
a[p]=a[p+1];
a[p+1]=t;
}
p++;
}
}
for(i=0;i<n;i++)
printf("%5d",a[i]);
getch();
}

Is This Answer Correct ?    42 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is faster array or arraylist?

463


Why is null not allowed in concurrenthashmap?

459


What are b tree keys?

448


What is difference between linear and non linear data structure?

573


How would you implement two stacks using a single array?

551






Is hashmap faster than arraylist?

453


Differentiate between queue and stack.

683


Why is treeset sorted?

516


Why quicksort is faster?

487


What is difference between stack and queue?

492


Is hashmap part of collection?

465


How expression trees are gets represented in data structure?

495


What is a binary search tree? Explain with example?

505


How does a treemap sort?

424


How many pointers are necessary to implement a simple linked list?

674