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

modify

上级 61532378
#ifndef QUICKSORT_H_
#define QUICKSORT_H_
//
// Include the C standard library header file here
//
#include <stdio.h>
//
// Other header files are included here
//
#include "Stack.h"
//
// Define the data structure here
//
//
// Declare the function here
//
void QuickSort(int* list, int left, int right);
//
......
......@@ -30,8 +30,10 @@ int Push(Stack* pS, int Elem)
//
// Stack full, push failed.
//
if(MAX_STACK_LENGTH-1 < pS->top)
return ;
if (MAX_STACK_LENGTH-1 < pS->top)
{
return;
}
pS->top++;
pS->buffer[pS->top] = Elem; // Insert the element at the top of the stack
......@@ -56,8 +58,10 @@ int Pop(Stack* pS)
//
// The stack is empty and the pop fails
//
if(StackEmpty(pS))
return ;
if (StackEmpty(pS))
{
return;
}
Elem = pS->buffer[pS->top];
pS->top--;
......
#ifndef STACK_H_
#define STACK_H_
//
// Include the C standard library header file here
//
//
// Other header files are included here
//
//
// Define the data structure here
//
......@@ -22,12 +17,12 @@
// Stack
typedef struct Stack{
typedef struct Stack
{
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
}Stack;
//
// Declare the function here
//
......@@ -37,12 +32,8 @@ int Push(Stack* pS, int Elem);
int Pop(Stack* pS);
int StackEmpty(Stack* pS);
//
// Declare global variables here
//
#endif /* STACK_H_ */
......@@ -25,8 +25,10 @@ int main(int argc, char* argv[])
//
// Output the sorted result
//
for(i=0; i<length; i++)
for (i=0; i<length; i++)
{
printf("%d ", list[i]);
}
return 0;
}
......@@ -43,7 +45,9 @@ parameter:
void QuickSort(int* list, int left, int right)
{
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
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论