c++ queries

Could someone help me out with the following
two queries please?

Query1
--
There is a function that receives an array of integers and it returns an array with all duplicates removed. So lets say it received {1, 2, 2, 3} it would return {1, 2, 3}. If you could only use 5 (and only 5) test arrays to test this function, which 5 would you use?

Query2
--
How do i write a function that accepts the head pointer to a linked list and returns the list with the links pointing the other way. For example, say you had h->1->2->3 (where h is the head pointer), it would return h->3->2->1.
[635 byte] By [chaturvedi] at [2007-11-19 9:41:38]
# 1 Re: c++ queries
Query1
--
There is a function that receives an array of integers and it returns an array with all duplicates removed. So lets say it received {1, 2, 2, 3} it would return {1, 2, 3}. If you could only use 5 (and only 5) test arrays to test this function, which 5 would you use? You can use std::vector or std::list to make your job simple using the unique standard algorithm.

The function that made the contents of your list/array unique is something like this -
void MakeMyArrayUnique (list <int> & lstIntegerArray)
{
lstIntegerArray.unique ();
}

This is how you would use it...

#include <list>
using namespace std;

int main(void)
{
// Create a list of integers using std::list
list <int> myIntegerArray;

// Insert integers into this array...
myIntegerArray.push_back (1);
myIntegerArray.push_back (2);
myIntegerArray.push_back (2);
myIntegerArray.push_back (3);

list <int> ::iterator iIntegerLocator;

// Print the original array
cout << "The original array is" << endl;
for ( iIntegerLocator = myIntegerArray.begin ()
; iIntegerLocator != myIntegerArray.end ()
; iIntegerLocator ++ )
cout << *iIntegerLocator << endl;

// REMOVE DUPLICATES
MakeMyArrayUnique (myIntegerArray);

// Print the new list
cout << "The array made unique is" << endl;
for ( iIntegerLocator = myIntegerArray.begin ()
; iIntegerLocator != myIntegerArray.end ()
; iIntegerLocator ++ )
cout << *iIntegerLocator << endl;

return 0;
}
You may also use std::vector, but, the advantage of std::list is that it contains a list::unique that does the job of making the list unique.

If you use std::vector, you will have to use the unique and also erase from <algorithm>.

This was solution to Query # 1...
Siddhartha at 2007-11-9 0:44:56 >
# 2 Re: c++ queries
Could someone help me out with the following
two queries please?
This for some reason sounds like homework...please understand that we usually don't do homeworks unless there is at least some code provided o show what you have already tried...
Andreas Masur at 2007-11-9 0:45:54 >
# 3 Re: c++ queries
i am trying to come up with some senareos for unit test cases..

For query 1 my test data would be what would be yours?.. Any suggestions appreciated. thx.

All values same
1) {1,1,1,1}
All values unique
2) {1,2,3,4}
First and last values same
3) {1,3,4,1}
Negative values in the list
4) {-1,2,1,3}
All values having duplicates.
5) {1,1,2,2}
chaturvedi at 2007-11-9 0:46:58 >
# 4 Re: c++ queries
i am trying to come up with some senareos for unit test cases..

For query 1 my test data would be what would be yours? Andreas was correct.
I don't understand what you are trying to get.

A solution that works for integers would work for any valid integer.

And, BTW, if you are doing Unit Testing, then you would consider this...
{a, 1, 3, z}
Siddhartha at 2007-11-9 0:48:03 >
# 5 Re: c++ queries
thx.. Nice one , I never thought of ascii.
chaturvedi at 2007-11-9 0:48:59 >