i need help with creating a delete function for my program, im getting really confused. Much help would be appreciated. THis program is due tomorrow. We have to use pointers and i get so confused. All other function written i have work but i can't get the delete function. Its very confusing for me. THanks in advance
struct NodeType //doubly linked list
{
string word;
int freq;
NodeType* prev;
NodeType* next;
};
class SortedType
{
public:
SortedType();
bool IsEmpty() const;
int LengthIs() const;
void FindItem(string& word, int& freq, bool& found);
void InsertFirst(string newword);
void InsertItemAfter(string newword);
void IncFreq();
void DeleteItem(string word, int& freq);
void ResetList();
void GetNextItem(string& word, int& freq, bool& moreNode);
void Print();
private:
NodeType *listData;
int length;
NodeType* currentPos;
};
void SortedType::InsertItemAfter(string newword)
{
NodeType* newNode;
NodeType* cpos;
newNode=new NodeType;
newNode->word=newword;
newNode->freq=1;
if(currentPos!=NULL) //case II and III
{
newNode->prev=currentPos;
newNode->next=currentPos->next;
if(currentPos->next!=NULL) //case II
currentPos->next->prev=newNode;
currentPos->next=newNode;
}
else //case I
{
newNode->prev=NULL;
newNode->next=listData;
listData->prev=newNode;
listData=newNode;
}
length++;
}
void SortedType::DeleteItem(string word, int& freq)
{
//need help creating this function
}