Skip to Content
C++ Data Structures and Algorithms
book

C++ Data Structures and Algorithms

by Wisnu Anggoro
April 2018
Intermediate to advanced content levelIntermediate to advanced
322 pages
6h 57m
English
Packt Publishing
Content preview from C++ Data Structures and Algorithms

Inserting an element

Due to the existence of the Previous pointer, we also need to refactor the inserting operation in the LinkedList data type. For the InsertHead() operation, the Previous pointer of the former Head must point to the new Head, so that we can have the new InsertHead() operation as follows:

template <typename T>void DoublyLinkedList<T>::InsertHead(T val){    // Create a new Node    DoublyNode<T> * node = new DoublyNode<T>(val);    // The current Head will no longer become a Head    // so the Next pointer of the new Node will    // point to the current Head    node->Next = Head;    // If the current Head is exist,    // the Previous pointer of the current Head    // should point to the node    if(Head != NULL)        Head->Previous = node; // The new Node now ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Data Structures and Algorithms Using C++

Data Structures and Algorithms Using C++

Ananda Rao Akepogu, Radhika Raju Palagiri
C++ Data Structures and Algorithm Design Principles

C++ Data Structures and Algorithm Design Principles

John Carey, Anil Achary, Shreyans Doshi, Payas Rajan
C++ Plus Data Structures, 6th Edition

C++ Plus Data Structures, 6th Edition

Nell Dale, Chip Weems, Tim Richards

Publisher Resources

ISBN: 9781788835213Supplemental Content