- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
thsort.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:3k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //----------------------------------------------------------------------------
- //Borland C++Builder
- //Copyright (c) 1987, 1998-2002 Borland International Inc. All Rights Reserved.
- //----------------------------------------------------------------------------
- //---------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <stdlib.h>
- #include "thsort.h"
- #include "sortthd.h"
- //---------------------------------------------------------------------
- #pragma resource "*.dfm"
- TThreadSortForm *ThreadSortForm;
- //---------------------------------------------------------------------
- Boolean ArraysRandom;
- TSortArray BubbleSortArray, SelectionSortArray, QuickSortArray;
- //---------------------------------------------------------------------
- __fastcall TThreadSortForm::TThreadSortForm(TComponent *Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::PaintArray(TPaintBox *Box, int const *A,
- int const ASize)
- {
- int i;
- TCanvas *canvas;
- canvas = Box->Canvas;
- canvas->Pen->Color = clRed;
- for (i=0; i <= ASize; i++)
- PaintLine(canvas, i, A[i]);
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::BubbleSortBoxPaint(TObject * /*Sender*/)
- {
- PaintArray(BubbleSortBox, EXISTINGARRAY(BubbleSortArray));
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::SelectionSortBoxPaint(TObject * /*Sender*/)
- {
- PaintArray(SelectionSortBox, EXISTINGARRAY(SelectionSortArray));
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::QuickSortBoxPaint(TObject * /*Sender*/)
- {
- PaintArray(QuickSortBox, EXISTINGARRAY(QuickSortArray));
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::FormCreate(TObject * /*Sender*/)
- {
- RandomizeArrays();
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::StartBtnClick(TObject * /*Sender*/)
- {
- TBubbleSort *bubble;
- TSelectionSort *selsort;
- TQuickSort *qsort;
- RandomizeArrays();
- ThreadsRunning = 3;
- bubble = new TBubbleSort(BubbleSortBox, EXISTINGARRAY(BubbleSortArray));
- bubble->OnTerminate = ThreadDone;
- selsort = new TSelectionSort(SelectionSortBox,
- EXISTINGARRAY(SelectionSortArray));
- selsort->OnTerminate = ThreadDone;
- qsort = new TQuickSort(QuickSortBox, EXISTINGARRAY(QuickSortArray));
- qsort->OnTerminate = ThreadDone;
- StartBtn->Enabled = False;
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::RandomizeArrays()
- {
- int i;
- if (! ArraysRandom)
- {
- Randomize();
- for (i=0; i < ARRAYSIZE(BubbleSortArray); i++)
- BubbleSortArray[i] = random(170);
- memcpy(SelectionSortArray, BubbleSortArray, sizeof(SelectionSortArray));
- memcpy(QuickSortArray, BubbleSortArray, sizeof(QuickSortArray));
- ArraysRandom = True;
- Repaint();
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TThreadSortForm::ThreadDone(TObject * /*Sender*/)
- {
- ThreadsRunning--;
- if (! ThreadsRunning)
- {
- StartBtn->Enabled = True;
- StartBtn->SetFocus();
- ArraysRandom = False;
- }
- }
- //---------------------------------------------------------------------