1 / 16

init_list

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.

midori
Download Presentation

init_list

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. init_list insert empty_list append delete destroy delete_node traverse list_iterator find_key allocate_node free_node malloc free

  2. 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

  3. 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

  4. Stacks dynamic arrays static array linked list Parenthesis checker Graphical region fill Infix to postfix

  5. Parenthesis Checker main push_char pop_char top_char init_stack push top empty_stack pop gets printf scanf

  6. 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.

  7. 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.

  8. /*************************************************/ /* 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 );

  9. /****************************************************/ /* 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 ; }

  10. 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; }

  11. 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 ; }

  12. 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 ) ; }

  13. 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.

  14. /****************************************/ /* 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 ; }

  15. 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 ; }

  16. 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 ; }

More Related