comparison PriorityQueue.c @ 3:500d0e2fabfb

made pure C and added .brch__defaul and eol handling
author Me@portablequad
date Sat, 11 Feb 2012 20:27:13 -0800
parents 4d8a1e0f4336
children
comparison
equal deleted inserted replaced
1:6c4a329945ba 2:24f2d054bd7f
3 * Licensed under GNU General Public License version 2 3 * Licensed under GNU General Public License version 2
4 * 4 *
5 * Author: hausers@cs.tu-berlin.de 5 * Author: hausers@cs.tu-berlin.de
6 */ 6 */
7 7
8 #include <limits.h>
9 #include <stdio.h>
10 #include <string.h>
11
12 #include "PriorityQueue.h" 8 #include "PriorityQueue.h"
13 #ifndef DEBUG
14 #include "../../VMS_Implementations/VMS_impl/vmalloc.h"
15 #endif
16 9
17 #define left(i) 2*i 10 #define left(i) 2*i
18 #define right(i) 2*i+1 11 #define right(i) 2*i+1
19 #define parent(i) i/2 12 #define parent(i) i/2
20
21 #ifdef DEBUG
22 #include <stdlib.h>
23 #define VMS__malloc malloc
24 #define VMS__free free
25 #endif
26 13
27 void swap (PrioQueueStruc *Q, int a, int b) { 14 void swap (PrioQueueStruc *Q, int a, int b) {
28 void *valTmp; 15 void *valTmp;
29 int keyTmp; 16 int keyTmp;
30 keyTmp= Q->data[a].key; 17 keyTmp= Q->data[a].key;
67 54
68 oldSize= Q->size; 55 oldSize= Q->size;
69 newSize= 2*oldSize; 56 newSize= 2*oldSize;
70 57
71 Q->maxSize= newSize; 58 Q->maxSize= newSize;
72 newData= VMS__malloc(Q->maxSize*sizeof(heapNode)); 59 newData= malloc(Q->maxSize*sizeof(heapNode));
73 oldData= Q->data; 60 oldData= Q->data;
74 61
75 memcpy(newData,oldData,Q->maxSize*sizeof(heapNode)); 62 memcpy(newData,oldData,Q->maxSize*sizeof(heapNode));
76 Q->data= newData; 63 Q->data= newData;
77 64
78 VMS__free(oldData); 65 free(oldData);
79 } 66 }
80 67
81 68
82 PrioQueueStruc* makeVMSPrioQ () { 69 PrioQueueStruc* makePrioQ () {
83 PrioQueueStruc *retQ; 70 PrioQueueStruc *retQ;
84 retQ= VMS__malloc(sizeof(PrioQueueStruc)); 71 retQ= malloc(sizeof(PrioQueueStruc));
85 retQ->maxSize= 1024; 72 retQ->maxSize= 1024;
86 retQ->data= VMS__malloc(retQ->maxSize*sizeof(heapNode)); 73 retQ->data= malloc(retQ->maxSize*sizeof(heapNode));
87 retQ->size= 0; 74 retQ->size= 0;
88 return retQ; 75 return retQ;
89 } 76 }
90 77
91 void* getFirstPrioQ (PrioQueueStruc *Q) { 78 void* getFirstPrioQ (PrioQueueStruc *Q) {
122 printf("} ... "); 109 printf("} ... ");
123 110
124 } 111 }
125 112
126 void freePrioQ (PrioQueueStruc *Q) { 113 void freePrioQ (PrioQueueStruc *Q) {
127 VMS__free(Q->data); 114 free(Q->data);
128 VMS__free(Q); 115 free(Q);
129 } 116 }