My Report

C++ STL Test – 4


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which function is used to check whether a given sequence is heap or not?

2. Which function is used to construct heap from given sequence of numbers?

3. What is the use of is_heap_until() function?

4. Elements in STL heap are removed in ________________________

5. What is the use of sort_heap() function in heap?

6. Which type of heap is implemented in STL heap?

7. What will be the output of the following C++ code?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	make_heap(v.begin(),v.end());
	v.push_back(110);
	push_heap(v.begin(), v.end());
	pop_heap(v.begin(), v.end());
	v.pop_back();
	cout<<v.front();
}

8. What will be the output of the following C++ code?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	make_heap(v.begin(),v.end());
	cout<<v.front();
}

9. What will be the output of the following C++ code?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {90, 47, 34, 23, 4, 35, 67};
	auto it = is_heap_until(v.begin(), v.end());
	for(auto i = v.begin(); i != it; i++)
		cout<<*i<<" ";
}

10. Which header file is required to use heap in your program?

11. Which function is used to insert an element into heap?

12. What is the use of front() function in heap?

13. Which of the following is correct syntax of making heap from a vector v?

14. What will be the output of the following C++ code?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	make_heap(v.begin(),v.end());
	v.push_back(110);
	push_heap(v.begin(), v.end());
	cout<<v.front();
}

15. What will be the output of the following C++ code?

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	vector <int> v = {1,5,23,90,15,35};
	cout<<is_heap(v.begin(), v.end());
	make_heap(v.begin(), v.end());
	cout<<is_heap(v.begin(), v.end());
}

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.