Priotity Queue Again

Hello there thanx to Mr. Hellios i can now modify the data inside a stl priority queue explicitly. But here is a problem i am facing. Here is some code to push value 0 to 9 (ranked 0 to 9) in a queue . And then i modify an element's rank to -1 and push a value of priority -1. And finally pop all and print 'em. but the two -1 ranked things are not coming at top, only the one i pushed is coming at top. is there any way i can make the changed node float to the top ??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <queue>

using namespace std ;

struct ss{
	int n ;
	int priority ;
} ;

struct compare{
	bool operator()(const ss &a,  const ss &b){
		return a.priority > b.priority ; 
	}
} ;
priority_queue < ss, vector < ss >, compare > Q ;

int main(){
	int i ;
	for (i = 0 ; i < 10 ; i++){
		ss t ;
		t.n = i ;
		t.priority = i ;
		Q.push(t) ;
	}
	ss *t = &Q.top() ;
	for (i = 0 ; i < 10 ; i++){
		cout << t[i].n << " " << t[i].priority << endl ;
	}
	t[9].priority = -1 ;
	t[10].n = 10 ;
	t[10].priority = -1 ;
	Q.push(t[10]) ;
	

	
	cout << endl << endl ;
	while (!Q.empty()){
		ss t ;
		t = Q.top() ;
		Q.pop() ;
		cout << t.n << " " << t.priority << endl ;
	}

}


0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9


10 -1
0 0
1 1
9 -1
2 2
3 3
4 4
5 5
6 6
7 7
8 8

Plz help.
You can't do that. You can't modify an element of the priority_queue without the priority_queue's knowledge
and then expect it to maintain proper sorting. To do what you want, you have to remove the element you
want to modify then re-add it as the modified value.
zee Thanx. :D
Topic archived. No new replies allowed.