SAL is the library for visualising sorting algorithms. SAL's animation is accomplished by insert animation function to the appropriate position.
SAL is not only animation but also showing statistics such as running time, data swapping number, and data reference number. Of cource, you can get these information without displaying animation.
SAL is implemented by using only Xlib, but mesureing running time code depends a bit machine library. This restriction will remove at future release. SAL can run under;
If you can run other plathome,please inform to me.Here, I use the simple sorting method to show how to use animation library.
In code red characteris functions to display animation.
#include "anim.h" #define DATA_SIZE 100 int data[DATA_SIZE]; void swap(i,j) { int tmp; tmp=data[i]; data[i]=data[j]; data[j]=tmp; } int main() { int i,j; /* Initializing data */ srandom((int)time(NULL)); AnimInit(DATA_SIZE,VIEW); for(i=0;i<DATA_SIZE;i++) { data[i]=(int)(DATA_SIZE*((double)random()/RAND_MAX)); AnimInitData(i,data[i]); } AnimShowData(0); /* Simple sort */ for(i=0;i<(DATA_SIZE-1);i++) for(j=i+1;j<DATA_SIZE;j++) { AnimHilightData(j); if(data[i]>data[j]) { swap(i,j); AnimSwapData(i,j); } AnimUnhilightData(j); } /* Display statistics information */ AnimShowStats(); } |
Swap count: 1731 Hilight count: 4950 Sorting time: 1342.9839[sec] |
Function | Description | |
---|---|---|
Initialize | AnimInit(int dataSize,int viewMode) | Initialize library. The viewMode is show animation(VIEW) or not show animation(NoVIEW). |
AnimInitData(int i,int value) | The i-th data value set to value. | |
AnimShowData() | Display initial data. | |
Animation | AnimSwapData(int i,j) | Swap i-th data and j-th one. |
AnimHilightData(int i) | Hilight i-th data. | |
AnimUnhilightData(int i) | Unhilight i-th data. | |
Parameter | AnimSetWaitTime(int time) | Set wait time to time(micro sec). |
AnimSetView(int value) | Change animation view mode. The value is show animation(VIEW) or not show animation(NoVIEW). | |
AnimSetAnimation(int value) | Change data swapping animation mode. The value is show animation(ANIM) or not show animation(NoANIM). | |
Statistisc | AnimShowStats() | Display statistics information. |
I use configure, so you must type below: