【发布时间】:2019-03-01 16:29:48
【问题描述】:
我是 C 新手,所以我们的课程从使用结构化编程开始。就参数 # 而言,一切都很好,但我很难理解错误消息。当尝试调用 enqueue 和 dequeue 时,它说 int 不能转换为 int*。在结构化编程以及传递值和地址方面,我很难理解指针。
bool Enqueque(int queue[], int* front, int* rear, int intialSize);
int Dequeque(int queue[], int* front, int* rear);
int GetCurrentSize(int queue[], int* front, int* rear);
int toString(int queue[], int* front, int* rear);
int main()
{
bool enqueueResult, dequeueResult, ifEmpty;
int UserOption = 0;
int initialSize = 10;
int* queue = (int*)malloc( initialSize * sizeof(int) );
for(int i = 0; i<initialSize; i++)
queue[i] = 0;
int* front, rear;
printf("This program implements Queues using structured programming. Enter "
"a number from 1 to 4 . \n"
"1. To enqueue a number \n"
"2. To dequeue a number \n"
"3. To get the current size of the queue \n"
"4. To see the contents within the queue \n");
scanf( "%d",UserOption );
switch(UserOption)
{
case 1:
enqueueResult = Enqueque(queue, front, rear, initialSize);
if(enqueueResult == true)
printf( "The number has been put into the queue!");
else
printf("The number was not able to be enqueued!");
break;
case 2:
dequeueResult = Dequeque( queue, front, rear );
if(dequeueResult == true)
printf( "The number has been dequeued!");
else
printf("The number wasn't able to be dequeued!");
break;
case 3:
printf( "The current size of the queue is: " + GetCurrentSize( queue, front, rear) );
break;
}
}
【问题讨论】:
标签: arrays pointers queue structure