codinasion-archive / codinasion-monorepo

Community Monorepo
https://codinasion.org
MIT License
52 stars 167 forks source link

Write a C program to implement selection sort #5329

Closed harshraj8843 closed 9 months ago

harshraj8843 commented 10 months ago

Description

Write a C program to implement selection sort

Selection sort is a sorting algorithm that selects the smallest element from an unsorted list in each iteration and places that element at the beginning of the unsorted list.

Pseudocode

procedure selection sort 
   list  : array of items
   n     : size of list

   for i = 1 to n - 1
   /* set current element as minimum*/
      min = i    

      /* check the element to be minimum */

      for j = i+1 to n 
         if list[j] < list[min] then
            min = j;
         end if
      end for

      /* swap the minimum element with the current element*/
      if indexMin != i  then
         swap list[min] and list[i]
      end if
   end for

end procedure

Example

Input  : [8, 5, 2, 6, 9, 3, 1, 4, 0, 7]
Output : [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
How to contribute - Comment `!assign` to assign this issue to yourself - Fork this repository - Create a new branch - Save the solution in `program/program/implement-selection-sort/ImplementSelectionSort.c` - Commit the changes - Create a pull request
codinasion-bot[bot] commented 10 months ago

👋🏻 Hey @harshraj8843

💖 Thanks for opening this issue 💖

A team member should be by to give feedback soon.

SapirKro commented 9 months ago

!assign

aaryan-sharmaa commented 9 months ago

!assign

codinasion-bot[bot] commented 9 months ago

Hey @aaryan-sharmaa, this issue is already assigned to @SapirKro! cc/ @codinasion/codinasion