/* Nathan DeBardeleben - ndebard@parl.clemson.edu * ECE 329 * Test program for the queue project. This forces only ints * into the queue and then reads them out as ints. Your queue * should work with those code but should handle the queue * elements as void *s. */ #include #include "queue.h" int main(int argc, char **argv) { struct queue *q; int *cur; int i, j, k, l, ret; i = 1; j = 2; k = 3; l = 4; q = Qinit(); cur = (int*)Qshow(q); if(cur != NULL) printf("\tERROR: CUR SHOULD BE NULL, QSHOW WRONG\n"); ret = Qremove(q, &i); printf("Removed an element from an empty q, return value = %d\n", ret); Qadd(q, &i); cur = (int*)Qshow(q); if(cur == NULL) printf("\tERROR: CUR SHOULD HAVE NOT BEEN NULL\n"); printf("cur = 1 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOUDL HAVE NOT BEEN NULL\n"); printf("cur = 1 ? = %d\n", *cur); Qadd(q, &j); Qadd(q, &k); Qadd(q, &l); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 2 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 3 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 4 ? = %d\n", *cur); printf("REMOVEING ELEMENT #3\n"); ret = 666; ret = Qremove(q, &k); printf("Removed 3? Ret = %d\n", ret); printf("REMOVEING ELEMENT #4\n"); ret = 666; ret = Qremove(q, &l); printf("Removed 4? Ret = %d\n", ret); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 2 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 1 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 2 ? = %d\n", *cur); cur = (int*)Qnext(q); if(cur == NULL) printf("\tERROR: CUR SHOULD NOT HAVE BEEN NULL\n"); printf("cur = 1 ? = %d\n", *cur); return 1; }