// File : Suitors.h
#ifndef SUITORSLIST_H
#define SUITORSLIST_H
#include <iostream>
using std::cout;
using std::endl;
class SuitorsList
{
private:
struct ListNode
{
int value;
ListNode * next;
};
ListNode * head;
public:
SuitorsList()
{
head = NULL;
}
void appendNode(int num);
void deleteNode(int num);
void displayList() const;
};
#endif;
// File : suitors.cpp
#include "Suitors.h"
void SuitorsList::appendNode(int num)
{
ListNode * newNode;
newNode = new ListNode;
newNode->value = num;
newNode->next = NULL;
if(!head)
{
head = newNode;
}
else
{
ListNode * nodePtr;
nodePtr = head;
while(nodePtr->next)
{
nodePtr = nodePtr->next;
}
nodePtr->next = newNode;
}
}
void SuitorsList::deleteNode(int num)
{
ListNode * nodePtr;
ListNode * prevPtr;
if(!head)
return;
if(head->value == num)
{
nodePtr = head->next;
delete head;
head = nodePtr;
}
else
{
nodePtr = head;
while(nodePtr && nodePtr->value != num)
{
prevPtr = nodePtr;
nodePtr = nodePtr->next;
}
if(nodePtr)
{
prevPtr->next = nodePtr->next;
delete nodePtr;
}
else
{
cout<< "value"<< num << "not found"<<endl;
}
}
}
void SuitorsList::displayList() const
{
ListNode * cur;
cur = head;
while(cur)
{
cout<< cur->value << " ";
cur = cur->next;
}
cout<<endl;
}
nageshkore 0 Newbie Poster
griswolf 304 Veteran Poster
nageshkore 0 Newbie Poster
griswolf 304 Veteran Poster
nageshkore 0 Newbie Poster
griswolf 304 Veteran Poster
nageshkore 0 Newbie Poster
griswolf 304 Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.