Sorted Sequences

I have run into an issue. I am having trouble conceptualizing how to find the most isolated element in a vector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// pre:  number is not empty;
//       number is sorted from smallest to largest
// post: The most isolated entry in number has been returned
double
mostIsolated(vector<double> & number)
{
	int size = number.size();
	int dist = 0;
	double result;
	for (int i = 0; i < size; i++) {
		if (number[i] == NULL ) {
			dist++;
			result = number[i + 1];
		}
		else if (number[i] != NULL) {
			dist = 0;
		}
		
	}
	return result;
} 

and i also need to be able to compare two lists of strings to pick out any letters that do not occur in both lists

1
2
3
4
5
6
7
8
9
10
11
12
// pre:  A and B are sorted.
// post: The number of strings in A that do not occur in B
//         has been returned.
int
unmatched(list<string> & A, list<string> & B)
{
	for (int i = 0; i < B.size(); i++) {

	}
	// STUB  STUB  STUB
	return -1;
} 

any help is greatly appreciated! just to re-iterate, the top section of code is to find the element in the vector that is furthest away from its nearest neighbor. The second piece of code is supposed to search through two lists of strings to find characters that do not appear in both list... if that doesn't make sense please ask me to clarify what you need clarify.
Last edited on
1. What does "most isolated" mean? All elements in an array are equidistant from their nearest neighbor.
2. The post-condition and your description of the problem do not match. Which is the correct one? Are you looking for the count of substrings of A that do not appear in B, or of characters of A that do not appear in B?
What does "furthest away" mean?

Does it mean element with largest
std::min( number[k] - number[k-1], number[k+1] - number[k] )

Look example at http://www.cplusplus.com/reference/numeric/adjacent_difference/
The set is {1, 2, 3, 5, 9, 11, 12}. Both 5 and 9 are "2 away" from their nearest neighbour. Two answers.


The second one: http://www.cplusplus.com/reference/algorithm/set_difference/
The Assignment description describes the first part as

The first problem is to find the most isolated number in a collection. The most isolated number is the number whose nearest neighbor is farthest away. The nearest neighbor of a number is another number in the collection that is closest in value to the number. If you imagine the number line, then the most isolated number will be the number who has the most distance between its two neighbors out of any other particular number from our problem set. The other number may be larger, equal to, or smaller than the number. For this instance, ties may be resolved using the neighbor with the lowest index.

and the second as
The second problem is a variation on the set difference problem. Given two collections of words, the problem is to count the number of words in the first collection that do not appear in the second collection.
Thanks kes, that looks like what im looking for
Topic archived. No new replies allowed.