Dec 102017
 
Stack and Queue Library written in Turbo C 2.0. LIB, no source code.
File SQLIB.ZIP from The Programmer’s Corner in
Category C Source Code
Stack and Queue Library written in Turbo C 2.0. LIB, no source code.
File Name File Size Zip Size Zip Type
SQLIB.DOC 7904 2572 deflated
SQLIB.H 2097 545 deflated
SQLIB.LIB 8498 3584 deflated

Download File SQLIB.ZIP Here

Contents of the SQLIB.DOC file













SQLIB

Stack and Queue Library

Version 1.0








written by

Richard Sedlak













Copyright 1991, C Prompt Computing, Inc.


INTRODUCTION:


The Stack and Queue Library was written because I personally
use many stacks and queues while programming. I have decided to
standardize the library and distribute it as "freeware". Feel
free to use as you wish and as long as you don't violate any of
my rights, copyrighted and otherwise. I do make one request
however, if you find it useful, please drop me a note in the mail
of even a copy of the program you use it in, if this doesn't
trouble you too much. The library is written in Turbo C 2.0 and
compiled with Borland's Turbo Librarian manager.



USAGE NOTES:


The library can be used with just about every data type
because it makes an extensive use of pointers. It is up to the
user of the library to typecast the pointers returned by the
functions in this library.



COMMENTS and QUESTIONS:


If you have any comments or questions, please send me a
letter.

Richard Sedlak
14229 Jib Street #11
Laurel, MD 20707


You can also reach me at the Boiling Point BBS,
(301) 490-3012. Send mail to Richard Sedlak.


DATA TYPES:



STACK

The STACK data type is provided for the use of multiple
stacks. This data type contains a pointer to the data and a
pointer to the next item on the stack.

Example:

/* CORRECT: This type is already a pointer */
STACK goodstack;

/* INCORRECT: This declares a pointer to a pointer */
STACK *badstack;


QUEUE

The QUEUE data type is provided for the use of multiple
queues. This data type contains a pointer to the data and a
pointer to the next item in the queue.

Example:

/* CORRECT: This type is already a pointer */
QUEUE goodqueue;

/* INCORRECT: This declares a pointer to a pointer */
QUEUE *badqueue;



Note: The STACK and QUEUE data type are just linked lists. The
difference exists in the operations performed. For instance, a
new item placed on the STACK becomes the first item in the linked
list whereas a new item placed in the queue would become the last
item in the list.


CONVENTIONS:


All functions and constants used by this library will have
"SQ_" as the first three characters to designate them as members
of the SQLIB. Also, there are usually two functions per data
type that appear to do the same operation. In fact, there are
two functions per data type. Function names that have a "v" as
the fourth character take an additional argument than do
functions that don't have the "v". For instance, SQ_push()
pushes an item onto the stack the library maintains whereas
SQ_vpush() pushes an item onto the stack that you declared as one
of your arguments.



DEFINED CONSTANTS:



SQ_ALLOCCURRENCE

Used by SQ_delete() and SQ_vdelete() to determine that all
occurrences of a searchkey should be deleted from the queue.


SQ_FIRSTOCCURRENCE

Used by SQ_delete() and SQ_vdelete() to determine that only
the first occurrence of a searchkey should be deleted from the
queue.


SQ_ERROR

Used as a return value to signal that an error occurred
while placing an item in the queue or on the stack.


SQ_NOERROR

Used as a return value to signal that an item was pushed on
the stack or placed in the queue.



FUNCTION EXPLANATIONS:



void *SQ_ptr(void *dataptr, int size_of_data);


SQ_ptr() takes the dataptr and size_of_data to create a new
pointer and to copy the information contained at dataptr into the
newly created pointer and returns the new pointer. This function
is useful in cases where you are building a stack or queue of
integers or floats.

Example:

int num;
int *numptr;

numptr = (int *) SQ_ptr(&num,sizeof(int));

Example:

int number;

if(SQ_push(SQ_ptr(&number,sizeof(int))) == SQ_ERROR)
{
printf("Error: Cannot push %d onto stack.\n",number);
exit(1);
}



char *SQ_charptr(char *strptr);


SQ_charptr takes strptr and creates a new pointer and copies
the characters from strptr into the new pointer. This function
becomes useful when placing character arrays on the stack or in
the queue.

Example:

char str[10];

if(SQ_push(SQ_charptr(str)) == SQ_ERROR)
{
printf("Error: Cannot push %s onto stack.\n",str);
exit(1);
}


STACK OPERATIONS:


void SQ_vinitstack(STACK *userstack);

SQ_vinitstack() initializes userstack to its proper initial
value. This function needs to called atleast once before a
the stack can be used for other operations.


void SQ_clearstack(void);
void SQ_vclearstack(STACK *userstack);

These functions are used to clear all items off the stack.
SQ_clearstack() takes no arguments since it works with the stack
declared within the library. SQ_vclearstack() works with user
declared stacks.


int SQ_push(void *item);
int SQ_vpush(STACK *userstack,void *item);

These functions are used to put a new item onto the stack.
SQ_push() uses the stack declared within the library and
SQ_vpush() is for user declared stacks. Both functions return
SQ_ERROR if an item cannot be pushed onto the stack and
SQ_NOERROR if the item can be pushed onto the stack.


void *SQ_pop(void);
void *SQ_vpop(STACK *userstack);

These functions are used to get an item from the stack.
SQ_pop() is used with the library declared stack and SQ_vpop() is
for user declared stacks. Both functions return NULL if the
stack is empty.


int SQ_stacksize(void);
int SQ_vstacksize(STACK userstack);

These functions return the number of items contained on the
stack. SQ_stacksize() returns the number of items contained on
the stack declared within the library and SQ_vstacksize() is for
user defined stacks.

QUEUE OPERATIONS:


void SQ_vinitqueue(QUEUE *userqueue);

SQ_vinitqueue() initializes userqueue to its proper starting
value. This function should be called atleast once if the user
declares his own queue.


void SQ_clearqueue(void);
void SQ_vclearqueue(QUEUE *userqueue);

These functions clear all items from the queue.
SQ_vclearqueue() is provided for user declared queues.


int SQ_queue(void *item);
int SQ_vqueue(QUEUE *userqueue,void *item);

These functions place the new item in the queue.
SQ_vqueue() is provided for user declared queues.


void *SQ_dequeue(void);
void *SQ_dequeue(QUEUE *userqueue);

These functions get the first item from the queue.
SQ_vdequeue() is provided for user declared queues.


int SQ_queuecount(void);
int SQ_vqueuecount(QUEUE userqueue);

These functions return the number of items contained in the
queue. SQ_vqueuecount() is provided for user declared queues.


void SQ_delete(void *function(),void *key,int FLAG);
void SQ_vdelete(QUEUE user,void *function(),void *key,int FLAG);


These functions delete items from the queue according to the
key, FLAG, and user defined function.

void *function()

Supplied by the user, this function must compare two
pointers and return NULL if they are not equal and not NULL
if they are equal. The only restriction on the data passed
is that they must be pointers.

void *key

This will be the patter that will be deleted from the
queue. It can be of any data type with the only restriction
being that the data type must be a pointer. The key will
be passed into the user defined function.

int FLAG

This value can be either SQ_FIRSTOCCURRENCE or
SQ_ALLOCCURRENCE.



 December 10, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)