mirror of
https://github.com/krahets/hello-algo.git
synced 2026-02-09 05:44:13 +08:00
fix: Update C code for compatibility with the MSVC compiler (#949)
* Replace VLA with malloc Replace VLA with malloc to make C code compatible with cl compiler on Windows. * Fix C code for CI compiler. * Fix C code compability to CI. * check the trigger
This commit is contained in:
@@ -73,16 +73,6 @@ void pop(ArrayQueue *queue) {
|
||||
queue->queSize--;
|
||||
}
|
||||
|
||||
/* 打印队列 */
|
||||
void printArrayQueue(ArrayQueue *queue) {
|
||||
int arr[queue->queSize];
|
||||
// 拷贝
|
||||
for (int i = 0, j = queue->front; i < queue->queSize; i++, j++) {
|
||||
arr[i] = queue->nums[j % queue->queCapacity];
|
||||
}
|
||||
printArray(arr, queue->queSize);
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
/* 初始化队列 */
|
||||
@@ -96,7 +86,7 @@ int main() {
|
||||
push(queue, 5);
|
||||
push(queue, 4);
|
||||
printf("队列 queue = ");
|
||||
printArrayQueue(queue);
|
||||
printArray(queue->nums, queue->queSize);
|
||||
|
||||
/* 访问队首元素 */
|
||||
int peekNum = peek(queue);
|
||||
@@ -105,7 +95,7 @@ int main() {
|
||||
/* 元素出队 */
|
||||
pop(queue);
|
||||
printf("出队元素 pop = %d ,出队后 queue = ", peekNum);
|
||||
printArrayQueue(queue);
|
||||
printArray(queue->nums, queue->queSize);
|
||||
|
||||
/* 获取队列的长度 */
|
||||
int queueSize = size(queue);
|
||||
@@ -120,7 +110,7 @@ int main() {
|
||||
push(queue, i);
|
||||
pop(queue);
|
||||
printf("第 %d 轮入队 + 出队后 queue = ", i);
|
||||
printArrayQueue(queue);
|
||||
printArray(queue->nums, queue->queSize);
|
||||
}
|
||||
|
||||
// 释放内存
|
||||
|
||||
Reference in New Issue
Block a user