Skip to content
Snippets Groups Projects
stack.c 1.19 KiB
Newer Older
  • Learn to ignore specific revisions
  • Douglas Guptill's avatar
    Douglas Guptill committed
    #include <stdlib.h>
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    	static struct node
    	{ int key; struct node *next; };
    	static struct node *head, *z, *t;
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    void stackinit_();
    void stackinit();
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void stackinit_() {stackinit();}
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void stackinit() 
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    	   {
    	     head = (struct node *) malloc(sizeof *head);
    	     z = (struct node *) malloc(sizeof *z);
    	     head->next = z; head->key=0;
    	     z->next = z;
    	     z->key = 0;
    	   }
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    void push_();
    void push();
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void push_(p) int *p; {push(p);}
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    	void push(p)
    
    Douglas Guptill's avatar
    Douglas Guptill committed
               int *p;
    	   {
    	     int v;
    	     v = *p;
    	     t = (struct node *) malloc(sizeof *t);	
    	     t->key = v; t->next = head->next;	
    	     head->next =t;	
    	   }
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    void pop();
    void pop_();
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void pop_(x) int *x; {pop(x);}
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    	void pop(x)
    
    Douglas Guptill's avatar
    Douglas Guptill committed
               int *x;
    	   {
    	     t = head->next; head->next = t->next;
    	     *x = t->key;
    	     free(t);
    	   }
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    void stackempty();
    void stackempty_();
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void stackempty_(i) int *i; {stackempty(i);}
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    	void stackempty(i)
    
    Douglas Guptill's avatar
    Douglas Guptill committed
              int *i;
    	  { 
    	    *i = 0;
                if(head->next == z) *i = 1;
              }
    
    Douglas Guptill's avatar
    Douglas Guptill committed
    void stackflush_();
    void stackflush();
    
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void stackflush_() {stackflush();}
    
    Douglas Guptill's avatar
    Douglas Guptill committed
            void stackflush()
    
    Douglas Guptill's avatar
    Douglas Guptill committed
               {
                 free(head);
                 free(z);
               }