• Build the min heap with no repeating values.

10,11,20,1512,22,24,19,22

i want to write a c++ program to build min heap which gets above values from user. remember this program should not alloduplicate values to enter. it should discard duplicate values. anybody can help me to write this program, i would be grateful,
due date is 11 july
1
2
3
4
5
6
7
8
9
10
11
#include<algorithm>
#include<set>
#include<iterator>
#include<iostream>


int main()
{
	std::set<int>  vals;
	std::copy( std::istream_iterator<int>(std::cin),  std::istream_iterator<int>(), std::inserter(vals, vals.end()) );	
}
Last edited on
it is allowing duplicate values, the condition is that it should not allow duplicate values, if duplicate value is entered, it should discard duplicate value.
thanks
there cannot be duplicated values in std::set
when i executed this program and entered values, it accepted duplicate values
what values did you input?
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
	std::set<int>  vals;
	std::copy( std::istream_iterator<int>(std::cin),  std::istream_iterator<int>(), std::inserter(vals, vals.end()) );
	
	std::set<int>::iterator it = vals.begin();
	while( it!= vals.end() )
	{
		std::cout << *it <<"  ";
		++it;
	}
}


I'm inputting this line
10 11 20 1512 22 24 19 22 Ctrl+Z
and it outputs:
10 11 19 20 22 24 1512
Last edited on
when user inputs the duplicate value, program should inform that you are putting duplicate values and program should discard the duplicate value immediately. please also clarify that is that a min heap program which you have written?

the required output should be as:

trying to insert value 2....
trying to insert value 3....
trying to insert value 6....
trying to insert value 2....
value 2 already exists, so discarding it...
trying to insert value 8....
trying to insert value 5....
trying to insert value 8....
value 8 already exists, so discarding it...

trying to insert value 9....

you have following values in heap

2 3 5 6 8 9


would you like to share you skype ID and email please?

your early reponse is needed. thanks
sorry but noone is going to write code for you, you should do that yourself I just wrote little example which may help you to write your own.
There is no any difficulty, just think and do it step by step.
Last edited on
muhammad ibrar, your bio says "Student of Masters in Computer Science" this should be a walk in the park for you.

Please try to do the work yourself and ask when you has specific problems not just general 'can you do this for me' rubbish.
Thanks for your valuable comments!
Ibrar bahe apni assignment khud bnaen thori bohat help her koi kar deta he per pura code koi ni likh k deta main ne sara code likh liya he assignment ka bus thora sa reh gya he apna vu id dy do main send kar dunga or agar ap mera group join karna chaho to join kar sakty ho
https://www.facebook.com/groups/VUprogrammers/
closed account (Dy7SLyTq)
personally i like the bubble sort algorithim
Topic archived. No new replies allowed.