提交 4879c609 创建 作者: 宋海霞's avatar 宋海霞

modify

上级 61532378
#ifndef QUICKSORT_H_ #ifndef QUICKSORT_H_
#define QUICKSORT_H_ #define QUICKSORT_H_
// //
// Include the C standard library header file here // Include the C standard library header file here
// //
#include <stdio.h> #include <stdio.h>
// //
// Other header files are included here // Other header files are included here
// //
#include "Stack.h" #include "Stack.h"
// //
// Define the data structure here // Define the data structure here
// //
// //
// Declare the function here // Declare the function here
// //
void QuickSort(int* list, int left, int right); void QuickSort(int* list, int left, int right);
// //
......
...@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem) ...@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem)
// //
// Stack full, push failed. // Stack full, push failed.
// //
if(MAX_STACK_LENGTH-1 < pS->top) if (MAX_STACK_LENGTH-1 < pS->top)
return ; {
return;
}
pS->top++; pS->top++;
pS->buffer[pS->top] = Elem; // Insert the element at the top of the stack pS->buffer[pS->top] = Elem; // Insert the element at the top of the stack
...@@ -56,8 +58,10 @@ int Pop(Stack* pS) ...@@ -56,8 +58,10 @@ int Pop(Stack* pS)
// //
// The stack is empty and the pop fails // The stack is empty and the pop fails
// //
if(StackEmpty(pS)) if (StackEmpty(pS))
return ; {
return;
}
Elem = pS->buffer[pS->top]; Elem = pS->buffer[pS->top];
pS->top--; pS->top--;
......
#ifndef STACK_H_ #ifndef STACK_H_
#define STACK_H_ #define STACK_H_
// //
// Include the C standard library header file here // Include the C standard library header file here
// //
// //
// Other header files are included here // Other header files are included here
// //
// //
// Define the data structure here // Define the data structure here
// //
...@@ -22,12 +17,12 @@ ...@@ -22,12 +17,12 @@
// Stack // Stack
typedef struct Stack{ typedef struct Stack
{
int buffer[MAX_STACK_LENGTH]; // Stack buffer int buffer[MAX_STACK_LENGTH]; // Stack buffer
int top; // Indicates the position at the top of the stack, not the number of elements in the stack int top; // Indicates the position at the top of the stack, not the number of elements in the stack
}Stack; }Stack;
// //
// Declare the function here // Declare the function here
// //
...@@ -37,12 +32,8 @@ int Push(Stack* pS, int Elem); ...@@ -37,12 +32,8 @@ int Push(Stack* pS, int Elem);
int Pop(Stack* pS); int Pop(Stack* pS);
int StackEmpty(Stack* pS); int StackEmpty(Stack* pS);
// //
// Declare global variables here // Declare global variables here
// //
#endif /* STACK_H_ */ #endif /* STACK_H_ */
...@@ -25,8 +25,10 @@ int main(int argc, char* argv[]) ...@@ -25,8 +25,10 @@ int main(int argc, char* argv[])
// //
// Output the sorted result // Output the sorted result
// //
for(i=0; i<length; i++) for (i=0; i<length; i++)
{
printf("%d ", list[i]); printf("%d ", list[i]);
}
return 0; return 0;
} }
...@@ -42,8 +44,10 @@ parameter: ...@@ -42,8 +44,10 @@ parameter:
*/ */
void QuickSort(int* list, int left, int right) void QuickSort(int* list, int left, int right)
{ {
int temp; // Temporary variables used to store partition elements int temp; // Temporary variables used to store partition elements
int i, j; // Cursors at both ends of the i, j divide and conquer region are used to adjust the data within the partition scope // Cursors at both ends of the i, j divide and conquer region
// are used to adjust the data within the partition scope
int i, j;
// //
// TODO: Add the code here // TODO: Add the code here
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论