Suppose we have a Queue as follows: E -> D -> C -> B
We maintain a head pointer to E and a tail pointer to B.
To add an element, we make a new queue item (say A), we set B->next = A, and set tail = A.
To delete an element, we let a temp pointer to the head (say tempHead = head), set head = E->next and deallocate tempHead.
examples:- delete this node (identified by a pointer)- insert a new node before this node- replace this node with another node
Assume the Linked list has following operations 1.node* insert(node* node, bool head); /* head = true if insertion at head else insertion at tail */ 2. node* remove(bool head); /* head = true if removal at head else removal at tail */ Now implement the stack functions as below. STK_RET push(node* pnode) { node* head; head = insert(pnode, true); /* insert the node at head */ if (head) return STK_OK; else return STK_NOK; } similarly pop can be implemented to remove the node at head Also the conventioin of inserting and removal from the tail can be used.
void pointer
Well, in a singly linked list you can only move forward, if the pointer you seek is behind your current position you'll have to cross the hole list to get there. In a doubly linked list you can simply move back as well as forward.... hope this helps...
In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.
Assume the Linked list has following operations 1.node* insert(node* node, bool head); /* head = true if insertion at head else insertion at tail */ 2. node* remove(bool head); /* head = true if removal at head else removal at tail */ Now implement the stack functions as below. STK_RET push(node* pnode) { node* head; head = insert(pnode, true); /* insert the node at head */ if (head) return STK_OK; else return STK_NOK; } similarly pop can be implemented to remove the node at head Also the conventioin of inserting and removal from the tail can be used.
examples:- delete this node (identified by a pointer)- insert a new node before this node- replace this node with another node
It is easier to insert into a singly linked list.
Yes it is possible to implement stack and queue using linked list
Yes, it is easy.
One advantage of a linked list (with pointers) is that it is fairly cheap to insert or delete an element - once you know where it is. A disadvantage is that getting a specific element - for example, the 1000th. element - is expensive.
void pointer
Well, in a singly linked list you can only move forward, if the pointer you seek is behind your current position you'll have to cross the hole list to get there. In a doubly linked list you can simply move back as well as forward.... hope this helps...
Macro operations are those not linked to individual types and invoked on objetcs - but rather general operations associated with the database as a whole.
In a doubly linked list, you can iterate backwards as easily as forwards, as each element contains links to both the prior and the following element. You can also insert or delete an element without needing to iterate and remember the prior element's link. This comes at a cost. You are adding storage to each element for the second link, and you are adding processing overhead to the insert and delete operation. You have to determine the tradeoff.
You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.
In linked list, there are various operations in linked list that you can perform on linked list, eg: adding new elements, deleting elements, getting the first element, getting the next element after an element, any many others.