+ 7
Simple if you already have a queue set up. So instead of push from back pop from front, we push to top, pop from top. we rewrite our push as NOTE: Skipping error checking such as isEmpty, isNull, doesnt exist, incompatible, etc. 1) new Node : n --Create new node --skipped inserting data and non relevant code 2) n -> next = head --Link new node to the head, so new node is now at the top 3) head = n --The new head is our new node There we can push to top now! Now pop 1) tempData = head->data --Store data for returning 2) newNode : n --Create new node 3) n = head --Store head node 4) head = head -> next --Our new head is the next node 5) delete n --Delete this from memory, we dont need it anymore 6) return tempData --Return what the previous head contained https://code.sololearn.com/ckbd0XvxqrmZ/?ref=app
17th May 2018, 12:26 AM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar