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

Removing an item from the LinkedList ADT

Similar to the inserting operation, the removing operation also has several cases, and they are:

  1. The removed item is in the Head, which is index = 0
  2. The removed item is in the Tail, which is index = N-1
  3. The removed item is in the other position of the linked list, where index = 1 to N-2

For case 1, the implementation is straightforward. We just need to point the Head pointer to the node which is pointed by the Next pointer of the current Head (in other words, the second element) and delete the first element of the linked list. Please see the following code:

template <typename T>void LinkedList<T>::RemoveHead(){    // Do nothing if list is empty    if(m_count == 0)        return;    // Save the current Head // to ...
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