/* * @(#)pqueue_test.c * * "Copyright (c) 2001 and The Regents of the University * of California. All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * * Author: Robert Szewczyk * * $Id: pqueue_test.c,v 1.2 2003/05/01 23:04:26 whong Exp $ */ #include #include typedef unsigned char uint8_t ; #define FAIL 0 #define SUCCESS 1 typedef int result_t ; #include "pqueue.h" char compare(int i, int j) { if (i>j) return 1; else if (j == i) return 0; else return -1; } int main(int argc, char ** argv) { int nElements, i, q, j; struct { char (*compare) (pq_element, pq_element); uint8_t size; uint8_t n_elements; pq_element heap[10]; } pqt; nElements = argc -1; pqueue_init(&pqt, 10, compare); for (j=0; j < 10; j++) { pqt.heap[j] = -1; } for (i=0; i < nElements; i++) { q = atoi(argv[i+1]); printf("%d %d\n", q, pqueue_enqueue(&pqt, q)); for (j=0; j < 10; j++) { printf("%d ", pqt.heap[j]); } printf("\n"); } for (i=0; i < nElements; i++) { printf("%d\n", pqueue_dequeue(&pqt)); } for (j=0; j < 10; j++) { printf("%d ", pqt.heap[j]); } printf("\n"); }