Friday, July 31, 2009

Hi can you help me with this? programming using algorithm in VB.net and C++... plz...=)?

the problem is%26gt;%26gt;%26gt; input 10 numbers, then arrange them in ascending and descending order. e.g.


input: 2,6,7,4,9,8,1,0,3,5





output: ascending%26gt;0,1,2,3,4,5,6,7,8,9


descending%26gt;9,8,7,6,5,4,3,2,1,0








VB.net and C++ are the prog. lang. to be used... thankz!

Hi can you help me with this? programming using algorithm in VB.net and C++... plz...=)?
With VB.net





Put the entries into an array: Dim NumArray as Integer(10)


Then sort the array: Array.Sort(NumArray)


or descending: Array.Reverse(NumArray)





There should be a C++ library for arrays as well, just not familiar with them.
Reply:#include %26lt;stdio.h%26gt;





//return p,q in ascending order


void Order(int *p,int *q) {


int temp;


if(*p%26gt;*q) {


temp=*p;


*p=*q;


*q=temp;


}// use %26lt; for the other way


}





//Buuble sorting of integer array A[]


void Bubble(int *a,int n) {


int i,j;





for (i=0; i%26lt;n; i++)


for (j=n-1; i%26lt;j; j--)


Order(%26amp;a[j-1], %26amp;a[j]);





}





void main() {


int i,n=10;


static int a[] = {0,2,9,5,4,8,7,6,3,1};





cout%26lt;%26lt;"\n\n Initial table A:\n";


for(i=0; i%26lt;n; i++)


cout%26lt;%26lt;a[i];





Bubble(a,n);





cout%26lt;%26lt;"\n\n Sorted table A:\n";


for(i=0; i%26lt;n; i++)


cout%26lt;%26lt;a[i];





cout%26lt;%26lt;"\n\n";


}





//end of file bubble.cpp
Reply:?hun?


No comments:

Post a Comment