Java Reference
In-Depth Information
int a;
lastProcessed++;
a=container [ lastProcessed ];
if (a < n) mark[a]= true ;
if (2
a+1) ;
if (3 a < n) add(3 a);
a+1 < n) add(2
}
public static void main( String [ ]
arg )
{ int i;
for (i=0;i < n ; i ++)
mark [ i ]= false ;
add (1) ;
while (!Empty())
process () ;
for (i=0;i < n ; i ++)
{ if (mark[ i ])
System . out . print ( i+ "" ); }
System . out . println ( "" );
}
}
Let us now run the program to list all integer elements less than 1000 and
belonging to
A
. We find:
1 3 7 9 15 19 21 27 31 39 43 45 55 57 63 79 81 87 91 93 111 115
117 127 129 135 159 163 165 171 175 183 187 189 223 231 235 237
243 255 259 261 271 273 279 319 327 331 333 343 345 351 367 375
379 381 387 405 447 463 471 475 477 487 489 495 511 513 519 523
525 543 547 549 559 561 567 639 655 663 667 669 687 691 693 703
705 711 729 735 751 759 763 765 775 777 783 811 813 819 837 895
927 943 951 955 957 975 979 981 991 993 999
8.3 Priority queues and heaps
As we have already attested by ourselves in airports, queues that ensure
the first in first out property are true only for passengers belonging to the
same traveling class. Air flight companies implement several grades for their
customers: Usually, it breaks down as economy, business and first classes. A
first class client arriving at any time will be served first even if economy clients
stand in the line long before. But another first class client will have to wait
until the first first class client goes on board to embark. This property of
 
Search WWH ::




Custom Search