2004-02-11 02:58:36 -05:00
|
|
|
/* LinkList: a circular linked list implementation for the TI-92+ graphing calculator */
|
|
|
|
|
|
|
|
//#define USE_TI92PLUS
|
|
|
|
|
|
|
|
#ifdef USE_TI92PLUS
|
|
|
|
|
|
|
|
#define ENABLE_ERROR_RETURN
|
|
|
|
#define OPTIMIZE_ROM_CALLS
|
|
|
|
#define SAVE_SCREEN
|
|
|
|
|
|
|
|
#include <tigcclib.h>
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "List.h"
|
|
|
|
|
|
|
|
void PrintList ( List *mylist ) {
|
|
|
|
Node *P;
|
2005-09-04 19:50:09 -04:00
|
|
|
unsigned long i = 0;
|
|
|
|
P = mylist->RootNode;
|
2004-02-11 02:58:36 -05:00
|
|
|
printf ( "[ " );
|
|
|
|
for ( i = 0; i < mylist->size; i++ ) {
|
|
|
|
printf ( "[%s] ", (char *)P->NodeElement );
|
|
|
|
if ( P->Next == NULL )
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
P = P->Next;
|
|
|
|
}
|
|
|
|
printf ( "]\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
short CompareString ( const Element Data1, const Element Data2 ) {
|
|
|
|
return strcmp ( Data1, Data2 );
|
|
|
|
}
|
|
|
|
|
2005-09-01 18:01:20 -04:00
|
|
|
void OutOfMemory ( List *mylist ) {
|
|
|
|
printf ( "Ran out of memory!\n" );
|
|
|
|
if ( mylist != NULL && mylist->RootNode != NULL )
|
|
|
|
MakeEmpty ( mylist );
|
|
|
|
exit ( 1 );
|
|
|
|
}
|
|
|
|
|
2004-02-11 02:58:36 -05:00
|
|
|
#ifdef USE_TI92PLUS
|
|
|
|
|
|
|
|
void _main ( void )
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int main ( void )
|
|
|
|
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
List mylist;
|
|
|
|
int i;
|
|
|
|
Element tmp;
|
|
|
|
Node *FindPtr;
|
|
|
|
|
|
|
|
#ifdef USE_TI92PLUS
|
|
|
|
ClrScr();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MakeList ( &mylist, CompareString );
|
2005-09-01 18:01:20 -04:00
|
|
|
if ( mylist.RootNode == NULL )
|
|
|
|
OutOfMemory ( &mylist );
|
2004-02-11 02:58:36 -05:00
|
|
|
PrintList ( &mylist );
|
|
|
|
|
|
|
|
for ( i = 0; i < 10; i++ ) {
|
|
|
|
tmp = malloc ( sizeof( Element ) * 3 );
|
|
|
|
sprintf ( tmp, "%d", i );
|
|
|
|
Push ( &mylist, tmp );
|
|
|
|
}
|
|
|
|
|
2005-09-04 19:50:09 -04:00
|
|
|
free ( Dequeue ( &mylist ) );
|
2004-02-11 02:58:36 -05:00
|
|
|
|
|
|
|
tmp = malloc ( sizeof( Element ) * 3 );
|
|
|
|
sprintf ( tmp, "%d", 20 );
|
2005-09-04 19:50:09 -04:00
|
|
|
FindPtr = Find ( &mylist, (Element)"5" );
|
2005-09-01 18:01:20 -04:00
|
|
|
if ( !InsertAt ( &mylist, tmp, FindPtr ) ) {
|
|
|
|
free ( tmp );
|
|
|
|
OutOfMemory ( &mylist );
|
|
|
|
}
|
2004-02-11 02:58:36 -05:00
|
|
|
|
|
|
|
tmp = malloc ( sizeof( Element ) * 4 );
|
|
|
|
sprintf ( tmp, "%s", "FOO" );
|
2005-09-01 18:01:20 -04:00
|
|
|
if ( !Enqueue ( &mylist, tmp ) ) {
|
|
|
|
free ( tmp );
|
|
|
|
OutOfMemory ( &mylist );
|
|
|
|
}
|
2004-02-11 02:58:36 -05:00
|
|
|
|
|
|
|
tmp = malloc ( sizeof( Element ) * 4 );
|
|
|
|
sprintf ( tmp, "%s", "BAR" );
|
2005-09-01 18:01:20 -04:00
|
|
|
if ( !Enqueue ( &mylist, tmp ) ) {
|
|
|
|
free ( tmp );
|
|
|
|
OutOfMemory ( &mylist );
|
|
|
|
}
|
2004-02-11 02:58:36 -05:00
|
|
|
|
|
|
|
PrintList ( &mylist );
|
|
|
|
MakeEmpty ( &mylist );
|
|
|
|
|
|
|
|
#ifdef USE_TI92PLUS
|
|
|
|
/* wait on keyboard input to continue */
|
|
|
|
ngetchx();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef USE_TI92PLUS
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|