A singly linked list class
The
class definition for a node
#include
<iostream>
#include
<string>
using
namespace std;
typedef
string listType;
class
node
{
public:
node
(listType);
voidsetData
(listType);
voidsetNext
(node*);
listTypegetData
() const;
node*
getNext () const;
private:
listType
data; node* next;
};
The functions for the node class
#include
"node.h"
node::node
(listType it)
{
//pre-condition:
it is the datum to be stored in the node
//post-condition:
it gets stored in the node
data =
it;
next =
NULL;
}
void
node::setData (listType it)
{
data =
it;
}
void
node::setNext (node* aNode)
{
next =
aNode;
}
listType
node::getData () const
{
return
data;
}
node*
node::getNext () const
{
return
next;
}
The class definition for the linked list
#include
"node.h"
class
linked
{
public:
linked ();
linked
(linked&);
linked
(listType [], int);
~linked
();
intgetSize
();
voidaddOnEnd
(listType);
voidinsertBefore
(int, listType);
voiddeleteLink
(int);
voidsetDataInLink
(int, listType);
listTypegetNthData
(int);
private:
node*
head;
node*
tail;
int size;
voiddeleteAll
();
node*
getNthAddress (int);
voiddeleteWithOneNode
();
voiddeleteAtBeginning
();
voiddeleteLast
();
voiddeleteInMiddle
(int);
};
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.