プライオリティ キューを作成していますが、PQ 配列を整数で埋めるのではなく、ポインタを構造体に割り当てています。PQ の初期化子と挿入関数の 2 つの構造体のコードを次に示します。
typedef struct HeapStruct *PriorityQueue;
typedef struct Customer *CustomerP;
struct HeapStruct {
int Capacity;
int Size;
int *Elements;
};
struct Customer {
float arrivalT;
float waitT;
float departureT;
float currentT;
CustomerP *siblingR; //Used for linked list
};
PriorityQueue Initialize() {
PriorityQueue H = (PriorityQueue) malloc(sizeof (struct HeapStruct));
CustomerP sentinal = malloc(sizeof (struct Customer));
sentinal->currentT = MinData;
H->Capacity = 101;
H->Size = 0;
H->Elements[0] = &sentinal; //Syntax Error
return H;
}
void Insert(CustomerP X, PriorityQueue H) {
int i;
if (IsFull(H)) {
printf("Priority queue is full");
return;
}
//Syntax errors
for (i = ++H->Size; H->Elements[i/2]->currentT > X->currentT; i /= 2)
H->Elements[i] = H->Elements[i/2];
H->Elements[i] = X;
}
そのため、Int 配列にポインターを配置して、H->Elements[i]->currentT などの比較を実行しようとしていますが、配列内の構造体へのポインターを処理し、構造体にアクセスする方法がわかりません。そこの。
誰かがこれの構文で私を助けてくれますか? 必要に応じて、より多くの情報を喜んで提供します。