Switch to full style
For C/C++ coders discussions and solutions
Post a reply

selection sort

Sat Apr 07, 2007 3:12 am

Simple selection sort algorithm(data structure concepts) implementation using C plus plus programming

cpp code
#include
#include

struct node
{
int data;
node *next;
};

class list
{
list() {head=current=tail=0;}

private:
node *head;
node *tail;
node *current;
public:
///put i at the beganning of j

//********************************copy function********************

void selectionsort(list &ok)
{

int max=0;
node *h;
for(h=head;h->next!=0;h=h->next)
if (h->data > max)
{ max=h->data;
ok.insert(max);
}

/*list *copy()
{list opop;

list opo;
if(head==0) coutnext!=0;head=head->next)
{node *noda=new node;
noda->data =h->data;

noda ->data=h->data;
if(opop.head==0)
{
opop.head->next=noda;
opop.head=opop.tail=noda;
}
else
{
opop.tail->next=noda;
opop.tail=noda;
opop.tail->next=0;

}

opop.display();



}


}
return 0;


}////////*/
//****************************************************************

list(int a[],int n)////insert the array of the size n in the list
{
head=tail=0;
for(int i=0;idata=elm;
if(head==0)
{
head=tail=n;
}
else
{
tail->next=n;
tail=n;
tail->next=0;
}
}
void display()
{
node *c=new node;
if(head==0)
{
coutnext!=0;c=c->next)
{
coutdatadatanext=head;}

void main()
{
list ok;
int size,size2;
cout>size;
int *n=new int[size];
for(int i=0;i>n[i];
}
list l(n,size);
l.display();

cout>size2;
int *u=new int[size2];
for(int p=0;p>u[p];
}

list k(u,size2);

l.append(k);
k.display();


l.selectionsort(ok);

ok.display();

}



Last edited by DrRakha on Wed Jan 23, 2013 2:18 pm, edited 4 times in total.
Reason: Code must be in code tag

Post a reply
  Related Posts  to : selection sort
 C++ Selection Sort     -  
 Help with selection sort for strings?     -  
 fill selection options from list     -  
 selection of checkbox in buttongroup in netbeans     -  
 Good looking selection box with image per option     -  
 validate age entered as selection box in javascript     -  
 calculate data from multiple selection     -  
 Feature selection: Statistical and Recursive examples     -  
 how to load the form elements depending on selection option     -  
 redirect page based on user selection radio button     -  

Topic Tags

C++ Sorting