I'm looking for a help to understand linked list. I have such a task: aclass DNAList:
- This class is a linked list of nodes that have pointers to (not copies of) DNA objects and at a minimum should contain:
- Appropriate constructor(s) and destructor
- Data members to store: Head pointer to list
- A DNANode struct or class that holds a pointer to a DNA object and a "next" pointer to a DNANode object (and a "prev" pointer if you're using a doubly-linked list).
- A push_back(DNA* newDNA) method that adds a node to the end of the list
- A find(int id) method that returns a DNA* if a DNA object with id exists in the list; otherwise it returns NULL
- An obliterate(int id) method that deletes the DNA entry with an accession number id and removes the corresponding node
- An int size() method that returns the number of elements in the list
First of all, I try to do push_back(DNA* newDNA) method. Any help, please?
Thank you.
DNAList.h
#ifndef DNALIST_H
#define DNALIST_H
#include <iostream>
#include <string>
#include "DNA.h"
class DNAList{
//data members
private:
DNA* headPtr;
public:
DNAList();
~DNAList();
struct DNANode;
void push_back(DNA* newDNA);
DNA* find(int id);
void obliterate(int id);
int size();
DNA* getHeadPtr(){
return headPtr;
}
void setHeadPtr(DNA* head){
headPtr= head;
}
};
#endif
DNAList.cpp
#include <iostream>
#include <string>
#include "DNAList.h"
//constrictor
DNAList::DNAList(){}
//destructor
DNAList::~DNAList(){
delete headPtr;
headPtr = NULL;
}
//struct that holds pointer to a DNA object and a "next" pointer to a
DNANode object
struct DNANode{
DNA* dnaPtr;
DNANode* next;
};
//
void push_back(DNA* newDNA){
//dnaPtr = new DNANode;
}
DNA* find(int id){
}
void obliterate(int id){
}
int size(){
return 0;
}
DNAandDNANode? Use one or the other, not both (the assignment says DNANode)DNANode objectdoing? That just looks like a compiler error.int DNAList::size() { return 0; }etc