Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2014/다빈치인재반/10회차

From ZeroWiki
Revision as of 05:48, 16 September 2014 by imported>trailblaze

계획

  • Priority_Queue
  • Heap
  • Heap 구현
  • STL에서 Priority_Queue 사용
  • Heap Sort


참여자

내용

Priority Queue

  • In computer science/data structures, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. If two elements have the same priority, they are served according to their order in the queue.
  • While priority queues are often implemented with heaps, they are conceptually distinct from heaps. A priority queue is an abstract concept like "a list" or "a map"; just as a list can be implemented with a linked list or an array, a priority queue can be implemented with a heap or a variety of other methods such as an unordered array.


Priority Queue in STL

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<queue>
using namespace std;
priority_queue <int> pq;
int v[100];
int main(void)
{
	int n = 10;
	srand(time(NULL));
	printf("Vector \n");
	for(int i = 0; i<n; i++){
		v[i] = rand() % 100;
		printf("%d ", v[i]);
	}
	printf("\n\n");
	for(int i = 0; i<n; i++){
		pq.push(v[i]);
	}
	
	printf("Priority Queue \n");
	while(!pq.empty()){
		printf("%d ", pq.top());
		pq.pop();
	}
	printf("\n\n");
}

Heap

후기

숙제


새싹교실/2014, 새싹교실/2014/다빈치인재반