array

correcting a function of an array, (arranging array elements)

Page 1 of 1

1 Replies - 722 Views - Last Post: 03 April 2009 - 01:08 PM Rate Topic: -----

#1 Prince of Darkness  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-March 09

array

Post icon  Posted 03 April 2009 - 01:00 PM

void readarray(int arr[10], int &t)
{ cout<<"enter the size of the array"<<endl;
  cin>>t;
  for (int i=0;i<t;i++)
  {cout<<"enter the element ";
   cin>>arr[i];
  }
}
  void printarray (int arr[10], int t)
  { for (int i=0;i<t;i++){
	  
	  cout<< arr[i]<<"	   ";
  }
  } 

  
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int arr[10];
	int t;
	readarray(arr,t);
	printarray(arr,t);
	
	return 0;
}





This is functioning completely well, i just need to add a function to it, Or modify the read function, so i can arrange the array elements while entering them, So when the array elements are printed out on the screen, they are arranged.
For example. for an array that has the size of t = 6, i might enter ( 90, 3, -1, 34, 4, 6)
but they are printed out on the screen arranged like this ( -1, 3, 4, 6, 34, 90 )


This is what i came up with so far

 void arrangearray(int arr[10], int t,)

 { 
int temp;
	  for (int j=1;j<t;j++)
	  { for (int f=1;f<t;f++)
	  { if (arr[j]>arr[f])
		 
			temp = arr[j];
	arr[j] = arr[f];
			arr[f] = temp;
	  }
	  }
  }






thanks in advance ;)

This post has been edited by Prince of Darkness: 03 April 2009 - 01:04 PM


Is This A Good Question/Topic? 0
  • +

Replies To: array

#2 Darkhack  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 208
  • Joined: 25-November 08

Re: array

Posted 03 April 2009 - 01:08 PM

There are lots of different sorting algorithms. Quicksort is usually the fastest for large data sets. For smaller data sets there is also insertion sort, selection sort, and bubble sort. Most people tend to stick with quicksort since its faster for the others with large data sets and performance is usual equal to the others for smaller sets.

Quicksort Tutorial: http://www.dreaminco...wtopic57199.htm
Insertion Sort: http://www.dreaminco...wtopic57287.htm
Selection Sort: http://www.dreaminco...wtopic57966.htm
Bubble Sort: http://en.wikipedia....by-step_example
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1