Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing alogorithms

Status
Not open for further replies.

Grizant

Programmer
Oct 6, 2002
7
US
How would I write function thats alinear search followed by a "move to front" of the found item with the following pre and post.

boolean movetoFrontSearch (
int a[], an array of size MAX
int n, the number of actual elements in the array
int target, value to be "searched for"
}
pre: n+1 <= MAX
post: { (RETURN = TRUE) => a[0] = target } and
{( RETURN = FALSE) => target not in a'[0...n-1]
and a[n] = target and
a'[0...n-1]=a[0..n-1] }

I know that targets that are not in the array should be inserted at the end of the array. Any help would be appreciated.
 
Is easy to use STL alogorithms. Try to

#include<vector>
#include<algorithm>
using namespace std;

and go on. More information you could find in MSDN. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top