Friday 21 April 2017

Sorting Algorithms /Session IX

1.SELECTION SORT

Write a C program to perform selection sort on an array of n elements.
Selection sort algorithm starts by comparing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort.(Refer below diagram ....)


click the link below for code :





2.INSERTION SORT

Write a C program to perform insertion sort on an array of n elements.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:
Refer sample output for formatting specs.



click the link below for code :


http://geekclues.blogspot.in/p/insertion-sort.html





3.BUBBLE SORT


Write a C program to perform bubble sort on an array of n elements.

Input Format:
Input consists of n+1 integers. The first integer corresponds to n, the number of elements in the array. The next n integers correspond to the elements in the array.

Output Format:
Refer sample output for formatting specs


click the link below for code :


http://geekclues.blogspot.in/p/Bubble Sort.html







4.Ascending Order


Write a program to find whether the given array is sorted in ascending order.

Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in asecending order. Print no if the array is not sorted in ascending order.

click the link below for code :

http://geekclues.blogspot.in/p/Ascending Order.html







5.
Descending Order Check


Write a program to find whether the given array is sorted in descending order.
Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in descending order. Print no if the array is not sorted in descending order.

click the link below for code :



6.Sorted Order Check

Write a program to find whether the given array is sorted in ascending or descending order.

Input Format:
Input consists of n+1 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the first array. Assume that the maximum value of n is 15.
Output Format:
Print yes if the array is sorted in ascending or descending order. Print no if the array is not sorted in ascending or descending order .



click the link below for code :

http://geekclues.blogspot.in/p/sorted-order-check.html

.

.


thankyou...




No comments:

Post a Comment