Demonstration of Selection Sort on Character Array
#include<iostream.h>#include<stdio.h>#include<string.h>#include<conio.h>
void selsort(char *items,int count){
// Local variable declarationint a,b,c;int exchange;
char t;
// Loop over the array of characters
for(a=0;a<count-1;++a){
exchange=0;
c=a;
t=items[a];
for(b=a+1;b<count;++b){if(items[b]<t){c=b;t=items[b];exchange=1;}
}
if(exchange){items[c]=items[a];items[a]=t;}}}
void main(){clrscr();char s[30];cout<<"Enter A String:";gets(s);selsort(s,strlen(s));cout<<"The String After Selection Sort:"<<s;getch();}
Like it on Facebook, Tweet it or share this article on other bookmarking websites.