Implementing Set in C++ without using STL


I want to Implementing Set in C++ without using STL.
I don't have problem with implementing.
I don't understand the concept. I don't know how can I show set in c++ with array?

Creating a set by using an array is part of implementing it, though, unless I'm misunderstanding your question. It wouldn't be very efficient for large data sets, but as a start you could just have a set contain an array of whatever type the set is, and then iterate through the set to see if there are any matches before adding a new item.

I'd say it's most likely for a set to either be implemented as a hash table or as a tree.

Or are you just talking about printing? If so, can you be more specific in what the issue with printing is?
Last edited on
Thank you for your reply,

I want to implement set with an array and then operator overloading << and >>
Now I need an idea for implementing set with an array

Read this:

A simple algorithm would be:

- iterate over the elements of the array as long as the new element < existing element
- When new element == existing element replace it otherwise insert.

The operator << and >> looks like this

std::ostream& operator<<(std::ostream& os, const T& obj)
    return os;

std::istream& operator>>(std::istream& is, T& obj)
    return is;
Instead of std::ostream and std::istream use your class name.
Registered users can post here. Sign in or register to post.