middleStack/Stack.c
/* Function to push an element to the stack */
Function to push an element to the stack
Function to push an element to the stack
void push(struct myStack *ms, int new_data)
{
    struct DLLNode* new_node =
               (struct DLLNode*) malloc(sizeof(struct DLLNode));
    new_node->data  = new_data;
    new_node->prev = NULL;
    new_node->next = ms->head;
    ms->count += 1;
	if(ms->count == 1)
	{
		ms->mid = new_node;
	}
	else
	{
		ms->head->prev = new_node;
		if(ms->count & 1)
			ms->mid = ms->mid->prev;
	}
}
void push ( struct myStack * ms , int new_data ) { struct DLLNode * new_node = ( struct DLLNode * ) malloc ( sizeof ( struct DLLNode ) ) ; new_node -> data = new_data ; new_node -> prev = NULL ; new_node -> next = ms -> head ; ms -> count += 1 ; if ( ms -> count == 1 ) { ms -> mid = new_node ; } else { ms -> head -> prev = new_node ; if ( ms -> count & 1 ) ms -> mid = ms -> mid -> prev ; } }
Function to push an element to the stack
Function to push an element to the stack
/* allocate DLLNode and put in data */ /* Since we are adding at the begining,
 *       prev is always NULL */ /* link the old list off the new DLLNode */ /* Increment count of items in stack */ //if count is odd