wordpress建站的利弊,tp框架网站开发参考文献,长沙网站seo哪家公司好,跨境电商建站1、建立顺序循环队列#xff0c;并在顺序循环队列上实现入队、出队基本操作。
#xff08;1#xff09;根据输入的队列长度n和各元素值建立一个循环顺序表表示的队列#xff08;循环队列#xff09;#xff0c;并输出队列中各元素值。
#xff08;2#xff09;将数据…1、建立顺序循环队列并在顺序循环队列上实现入队、出队基本操作。
1根据输入的队列长度n和各元素值建立一个循环顺序表表示的队列循环队列并输出队列中各元素值。
2将数据元素e入队并输出入队后的队列中各元素值。
3将循环队列的队首元素出队并输出出队元素的值和出队后队列中各元素值。 #include stdio.h
#include stdlib.h#define MAX_SIZE 100typedef struct {int data[MAX_SIZE];int front; // 队首指针int rear; // 队尾指针
} CircularQueue;// 初始化队列
void initQueue(CircularQueue *queue) {queue-front 0;queue-rear 0;
}// 判断队列是否为空
int isEmpty(CircularQueue *queue) {return queue-front queue-rear;
}// 判断队列是否已满
int isFull(CircularQueue *queue) {return (queue-rear 1) % MAX_SIZE queue-front;
}// 入队
void enqueue(CircularQueue *queue, int e) {if (isFull(queue)) {printf(队列已满无法入队。\n);return;}queue-data[queue-rear] e;queue-rear (queue-rear 1) % MAX_SIZE;
}// 出队
int dequeue(CircularQueue *queue) {if (isEmpty(queue)) {printf(队列为空无法出队。\n);return -1;}int e queue-data[queue-front];queue-front (queue-front 1) % MAX_SIZE;return e;
}// 输出队列中的元素
void printQueue(CircularQueue *queue) {if (isEmpty(queue)) {printf(队列为空。\n);return;}printf(队列中的元素为);int i queue-front;while (i ! queue-rear) {printf(%d , queue-data[i]);i (i 1) % MAX_SIZE;}printf(\n);
}int main() {CircularQueue queue;initQueue(queue);int n;printf(请输入队列长度n);scanf(%d, n);printf(请输入队列中的元素值);for (int i 0; i n; i) {int value;scanf(%d, value);enqueue(queue, value);}printQueue(queue);int e;printf(请输入要入队的元素值);scanf(%d, e);enqueue(queue, e);printQueue(queue);int dequeued dequeue(queue);if (dequeued ! -1) {printf(出队元素的值为%d\n, dequeued);}printQueue(queue);return 0;
} 2、请利用所学栈的知识设计一个进制转换器实现十进制到八进制的转换 #include stdio.h
#include stdlib.h#define MAX_SIZE 100typedef struct {int data[MAX_SIZE];int top;
} Stack;// 初始化栈
void initStack(Stack *stack) {stack-top -1;
}// 判断栈是否为空
int isEmpty(Stack *stack) {return stack-top -1;
}// 判断栈是否已满
int isFull(Stack *stack) {return stack-top MAX_SIZE - 1;
}// 入栈
void push(Stack *stack, int e) {if (isFull(stack)) {printf(栈已满无法入栈。\n);return;}stack-data[stack-top] e;
}// 出栈
int pop(Stack *stack) {if (isEmpty(stack)) {printf(栈为空无法出栈。\n);return -1;}return stack-data[stack-top--];
}// 十进制到八进制转换
void decimalToOctal(int decimal) {Stack stack;initStack(stack);while (decimal 0) {int remainder decimal % 8;push(stack, remainder);decimal / 8;}printf(八进制数为);while (!isEmpty(stack)) {printf(%d, pop(stack));}printf(\n);
}int main() {int decimal;printf(请输入一个十进制数);scanf(%d, decimal);decimalToOctal(decimal);return 0;
}