Skip to content

Conversation

@Gonglja
Copy link
Contributor

@Gonglja Gonglja commented Jan 28, 2023

If this PR is related to coding or code translation, please fill out the checklist.

  • I've tested the code and ensured the outputs are the same as the outputs of reference codes.
  • I've checked the codes (formatting, comments, indentation, file header, etc) carefully.
  • The code does not rely on a particular environment or IDE and can be executed on a standard system (Win, macOS, Ubuntu).

@vercel
Copy link

vercel bot commented Jan 28, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
hello-algo ⬜️ Ignored (Inspect) Jan 29, 2023 at 6:22AM (UTC)

@krahets
Copy link
Owner

krahets commented Jan 28, 2023

Could you copy&paste the console outputs to this PR? Thanks!

@Gonglja
Copy link
Contributor Author

Gonglja commented Jan 28, 2023

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;
Copy link
Owner

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

Copy link
Contributor Author

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++) {
Copy link
Owner

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);
Copy link
Owner

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.

Copy link
Owner

@krahets krahets left a 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.

Copy link
Owner

@krahets krahets left a 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.

@krahets krahets merged commit 9c2caad into krahets:master Jan 30, 2023
@krahets krahets added the code Code-related label Jan 30, 2023
@Gonglja Gonglja deleted the feat-queue-array-impl branch February 1, 2023 10:07
@Gonglja Gonglja mentioned this pull request Mar 18, 2023
51 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code Code-related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants