Please Note:
I've been warned here by professionals for solving HomeWorks so I don't provide the solution(source code) for your Question.
You are probably looking for Containers there are various containers in C++ STL and to my knowledge almost many provides the solution you are looking for.
Example Solved Using set[This can be done using list, deque etc and etc]
Set will be automatically sorted and could not add duplicate elements(If you needed unsorted and could duplicates then refer something about Sequence containers).
set<int> newSet;
newSet.insert(9);
newSet.insert(8);
newSet.insert(1);
newSet.insert(0);
newSet.insert(4);
newSet.insert(6);
set<int>::iterator itr1 = newSet.begin();
set<int>::iterator itr2 = newSet.end();
for (set<int>::iterator itr = itr1; itr != itr2; itr++)
{
cout << *itr<<endl;
}
pair<set><int>::iterator, bool> tell;
tell = newSet.insert(8);
if (tell.second == false)cout << "Element present in the set" << endl;
cin.get();
return 0;
</int></set></int></int></int></int>
I hope I have explained something but please refer about STL for more info.
If you have any doubts please feel free to ask me.