![]() ![]() well, i tried them separately and they worked, but i want a single stack performing all the functions, and here tow separate stacks are being created. If you only pass in the head pointer any local update you make to that pointer will not be seen by the caller. hi, i tried implementing the stack with pop front, pop back ,push front and push back functions. C is 'Call by value' meaning copies of parameters are passed into functions. Stack can be implemented using Arrays and LinkedLists. Operations on Stack occur only at one end called as the TOP of the stack. So now we have two variables pointing to the same address.Įven if, in any case, this code was meant to say, new_node = head.prev, that also does not make sense, because the head.prev will be null at this point, and new_node will then point to a null. The standard way to handle linked lists in C is to have the push and pop functions automatically update the head pointer. A Stack is a Linear Data Structure in which Operations are performed in a specific order known as LIFO (Last In First Out) or FILO (First In Last Out). This doesn't even make sense because the variable 'head' will also hold new_node. Your typedefs should be: typedef struct stackNode StackNode typedef StackNode StackNodePtr No idea why you're against using typedef - it tends to make the code a lot more readable. Elements can be pushed or popped from one end only. Stack supports operations such as push, pop, size, peek, and is Empty. In a doubly linked list, each node contains two links the first link points. Stack can be represented using nodes of a linked list. push() function is used to insert new elements into the Stack and pop(). on the heap) and the functions local variables get pushed onto the stack. Stack is a linear data structure that follows the Last in, First Out Principle (LIFO). The variable head.prev will now hold new-node. This line: typedef struct StackNode StackNodePtr is wrong by the way. Adding data is called pushing onto the stack, and removing data is called. Right here, it appears to me that it's storing the address of the new_Node into the variable head.prev. This is a code that adds a node at the front of the doubly linked list. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |