160 likes | 344 Views
init_list. insert. empty_list. append. delete. destroy. delete_node. traverse. list_iterator. find_key. allocate_node. free_node. malloc. free. main. add_poly. read_poly. write_poly. cmp_degree. write_term. term_insert. term_delete. init_list. insert. empty_list. append.
E N D
init_list insert empty_list append delete destroy delete_node traverse list_iterator find_key allocate_node free_node malloc free
main add_poly read_poly write_poly cmp_degree write_term term_insert term_delete init_list insert empty_list append delete destroy delete_node traverse list_iterator find_key allocate_node free_node malloc free printf scanf
Radix Sort main refill getdigit appendanumber getnextnumber init_list insert empty_list append delete destroy delete_node traverse list_iterator find_key allocate_node free_node malloc free printf scanf
Stacks dynamic arrays static array linked list Parenthesis checker Graphical region fill Infix to postfix
Parenthesis Checker main push_char pop_char top_char init_stack push top empty_stack pop gets printf scanf
gets (page 772 in the ANSI C book) #include <stdio.h> char *gets( char *storage ) ; Reads the next line from the standard input. The “next line” consists of all characters up to and including the next newline character or the end of file, whichever come first. If at least one character is read, gets stores at address storage all characters read except the newline that is discarded and adds a terminating null to the end of the line. Notice that gets never stores a newline character. If no characters are stored or an error occurs, gets returns NULL; otherwise, gets returns the address storage.
page 108 The switch statement on page 108 needs to altered to allow for the { symbol and the } symbol. There is no need for the - symbol and the “ symbol.
/*************************************************/ /* stack.h */ /*************************************************/ #define MAXSTACKSIZE 100 #include "globals.h" typedef struct { generic_ptr base[MAXSTACKSIZE]; generic_ptr *top ; } stack ; extern status init_stack( stack *p_S ) ; extern bool empty_stack ( stack *p_S ); extern status push ( stack *p_S , generic_ptr data ); extern status pop ( stack *p_S , generic_ptr *p_data); extern status top ( stack *p_S , generic_ptr *p_data );
/****************************************************/ /* stack.c */ /****************************************************/ #include "stack.h" #include "globals.h" #define current_stacksize( p_S ) ( (p_S) -> top - (p_S)->base ) extern status init_stack ( stack *p_S ) { p_S -> top = p_S -> base ; return OK ; }
extern bool empty_stack (stack *p_S) { return ( ( p_S -> top == p_S->base) ? TRUE : FALSE ) ; } extern status push ( stack *p_S, generic_ptr data ) { if ( current_stacksize( p_S) == MAXSTACKSIZE ) return ERROR ; *p_S->top = data ; p_S -> top++ ; return OK; }
extern status pop( stack *p_S, generic_ptr *p_data ) { if ( empty_stack ( p_S ) == TRUE ) return ERROR ; p_S -> top-- ; *p_data = *p_S->top ; return OK ; }
extern status top (stack *p_S , generic_ptr *p_data ) { if ( pop ( p_S, p_data ) == ERROR ) return ERROR ; return push ( p_S , *p_data ) ; }
Careful Looking at the Figures Although the code in the textbook relies upon generic pointers to the data, the figures do not generally reflect this. I think the authors/publishers wanted to have simpler pictures. For example, the picture on page 111 showing stack containing a and b. The real structure would contain a pointer to a and pointer to b.
/****************************************/ /* stack_interface.c */ /****************************************/ #include "stack.h" #include "stdio.h" #include "globals.h" #include <stdlib.h> extern status push_char ( stack *p_S , char c ) { char *p_c = (char *) malloc (sizeof(char)) ; if ( p_c == NULL ) return ERROR ; *p_c = c ; if (push (p_S, (generic_ptr) p_c) == ERROR ) { free (p_c); return ERROR ; } return OK ; }
extern status pop_char ( stack *p_S , char *p_c ) { char *p_data ; if ( pop ( p_S, (generic_ptr *) &p_data ) == ERROR ) return ERROR ; *p_c = *p_data ; free (p_data) ; return OK ; }
extern status top_char ( stack *p_S , char *p_c ) { char *p_data ; if ( top (p_S, (generic_ptr *) &p_data ) == ERROR ) return ERROR ; *p_c = *p_data ; return OK ; }