Simple Sort Animation Library:SAL


[Japanese|English]

Table of contents


Preface

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.


Requirment


Sample code and screenshot

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();
	  }
	
[ScreenShot]
Swap count:     1731
Hilight count:  4950
Sorting time:   1342.9839[sec]
	    
Output statistics information

Functions in this library

FunctionDescription
InitializeAnimInit(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.
AnimationAnimSwapData(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.
ParameterAnimSetWaitTime(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).
StatistiscAnimShowStats()Display statistics information.

Download

SAL archive include some sample code, such as:

Install

I use configure, so you must type below:

  1. % ./configure
  2. % xmkmf
  3. % make Makefiles
  4. % make

Link


Takeshi Mutoh <mutoh@info.nara-k.ac.jp>