HELP with c++ code..
Having trouble with this method.
bool List::remove(int index){
//remove the Planet object at index, decreasing the
size of the Vector by 1.
//return true on successful deletion or false if the
index is out of bounds
}
Here is the header file..
#ifndef LIST_H
#define LIST_H
#include "Planet.h"
#include <iostream>
class Node
{
friend class List; //allow list class to access
private fields
//https://www.geeksforgeeks.org/friend-class-function-cpp/
private:
Planet *planet;
Node *next;
Node *prev;
public:
Planet* getPlanet(){return
this->planet;}
Node(Planet * p);
};
class List{
private:
Node *head;
Node *tail;
public:
List();
~List();
void insert(int index, Planet *
p);
Planet * read(int index);
bool remove(int index);
unsigned size();
};
#endif
CODE
bool List::remove(int index)
{
/* if list in NULL or invalid position is given */
if (*head == NULL || index < 0)
return false;
struct Node* current = *head;
int i;
for (int i = 1; current != NULL && i < index; i++)
current = current->next;
/* if 'n' is greater than the number of nodes
in the doubly linked list */
if (current == NULL)
return false;
/* If node to be deleted is head node */
if (*head == current)
*head = current->next;
/* Change next only if node to be deleted is NOT
the last node */
if (current->next != NULL)
current->next->prev = current->prev;
/* Change prev only if node to be deleted is NOT
the first node */
if (current->prev != NULL)
current->prev->next = current->next;
return true;
}
HELP with c++ code.. Having trouble with this method. bool List::remove(int index){ //remove the Planet...