-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Add queue array impl in C #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
|
Could you copy&paste the console outputs to this PR? Thanks! |
|
Ok, no problem, the following is C:\Windows\system32\wsl.exe --distribution Ubuntu-22.04 --exec /bin/zsh -c "cd /mnt/d/03Data/01Git/hello-algo/codes/c/cmake-build-debug/chapter_stack_and_queue && /mnt/d/03Data/01Git/hello-algo/codes/c/cmake-build-debug/chapter_stack_and_queue/array_queue"
队列 queue = [1, 3, 2, 5, 4]
队首元素 peek = 1
出队元素 poll = 1,出队后 queue = [3, 2, 5, 4]
队列长度 size = 4
队列是否为空 = false
第 0 轮入队 + 出队后 queue = [2, 5, 4, 0]
第 1 轮入队 + 出队后 queue = [5, 4, 0, 1]
第 2 轮入队 + 出队后 queue = [4, 0, 1, 2]
第 3 轮入队 + 出队后 queue = [0, 1, 2, 3]
第 4 轮入队 + 出队后 queue = [1, 2, 3, 4]
第 5 轮入队 + 出队后 queue = [2, 3, 4, 5]
第 6 轮入队 + 出队后 queue = [3, 4, 5, 6]
第 7 轮入队 + 出队后 queue = [4, 5, 6, 7]
第 8 轮入队 + 出队后 queue = [5, 6, 7, 8]
第 9 轮入队 + 出队后 queue = [6, 7, 8, 9]
Process finished with exit code 0
|
| /* Driver Code */ | ||
| int main() { | ||
| /* 初始化队列 */ | ||
| int capacity = 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 4 spaces for indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 4 spaces for indentation
Ok, I reformatted some code, sorry for the different results due to just cutting to clion using different tools to format differently
| int cap = capacity(queue); | ||
| int arr[siz]; | ||
| // 拷贝 | ||
| for (int i=0, j=queue->front; i<siz; i++, j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format the code
for (int i = 0, j = queue->front; i < siz; i++, j++)
Recommend using a code formatting tool.
|
|
||
| /* 访问队首元素 */ | ||
| int peek(ArrayQueue *queue) { | ||
| assert(size(queue)!=0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert(size(queue) != 0);
Please check the format of other codes.
krahets
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please address the comments.
krahets
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Now merge it.
If this PR is related to coding or code translation, please fill out the checklist.