[try Beta version]
Not logged in

 
• Build the min heap with no repeating values.

Jul 10, 2013 at 11:36am
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
Jul 10, 2013 at 12:07pm
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 Jul 10, 2013 at 12:07pm
Jul 10, 2013 at 12:26pm
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
Jul 10, 2013 at 12:30pm
there cannot be duplicated values in std::set
Jul 10, 2013 at 12:52pm
when i executed this program and entered values, it accepted duplicate values
Jul 10, 2013 at 1:00pm
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 Jul 10, 2013 at 1:20pm
Jul 10, 2013 at 1:36pm
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
Jul 10, 2013 at 1:47pm
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 Jul 10, 2013 at 1:51pm
Jul 10, 2013 at 1:54pm
closed account (z05DSL3A)
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.
Jul 10, 2013 at 2:12pm
Thanks for your valuable comments!
Jul 10, 2013 at 7:25pm
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/
Jul 10, 2013 at 7:54pm
closed account (Dy7SLyTq)
personally i like the bubble sort algorithim
Topic archived. No new replies allowed.