1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#include <iostream>
#include<string>
using namespace std;
class LL;
class Node
{
friend class LL;
private:
string firstName;
string lastName;
string phoneNumber;
Node * nextRecord;
};
class LL
{
private:
Node* head;
void destroy();
//to dereference then put parenthesis.
public:
LL();
LL(const LL&);
~LL();
void append(string, string, string);
void insertAtBeginning(string, string, string);
void insertByPos(string, string, string, int);
void print();
void searchByName(string, string);
void updateNumber(string, string, string);
void removeRecord(string, string);
void reverse();
};
//--------------------------------------------
// the default constructor
LL::LL()
{
head=nullptr;
}
//--------------------------------------------
// the copy constructor
LL::LL(const LL& source)
{
// Node *nodeptr;
//head=nullptr;
}
//----
}
//--------------------------------------------
// the destructor
LL::~LL()
{
Node *nodeptr ;
Node *nextNode;
nodeptr = head;
while ( nodeptr!= nodeptr)
{
nextNode = nodeptr-> nextRecord;
delete nodeptr;
nodeptr = nextNode;
}
}
//--------------
void LL::print ()
{
Node *nodeptr=head;
while(nodeptr)
{
//display
cout << nodeptr -> firstName<< " " << nodeptr -> lastName << " " << nodeptr -> phoneNumber << endl << endl;
//move thru the next node
nodeptr = nodeptr -> nextRecord;
}
}
//--------------------------------------------
// search for a particular person in the list and print the
// corresponding phone number
void LL::searchByName (string fName, string lName)
{
}
}
// create a node and insert the node at the position pos
void LL::insertByPos (string fName, string lName, string phone, int pos)
{
Node *newNode;
Node *nodePtr;
Node *previousNode = NULL;
newNode = new Node;
newNode -> firstName = fName;
newNode -> lastName=lName;
newNode -> phoneNumber =phone;
if ( head==NULL )
{
return;
}
if (pos ==0)
{
newNode -> nextRecord= head;
head = newNode;
}
int i =0;
nodePtr = head;
while ( nodePtr != NULL && i < pos)
{
previousNode = nodePtr;
nodePtr= nodePtr -> nextRecord;
i++;
}
newNode -> nextRecord = previousNode -> nextRecord;
previousNode -> nextRecord = newNode;
}
void LL::updateNumber(string fName, string lName, string newPhone)
{
}
//--------------------------------------------
// Destroy all the nodes in the list
void LL::destroy()
{
}
//--------------------------------------------
// traverse the list and reverse the list nodes so the last node
// becomes the first and the first node becomes the last one
void LL:: reverse()
{
}
//--------------------------------------------
int main ()
{
LL list1;
list1.append ("Mayssaa", "Najjar", "878-635-1234");
list1.insertAtBeginning ("Jim", "Meyer", "337-465-2345");
list1.append ("Joe", "Didier", "352-654-1983");
list1.insertByPos ("Adam", "James", "202-872-1010", 2);
list1.insertAtBeginning("Nancy", "Garcia", "617-227-5454");
list1.print();
/*
list1.searchByName ("Nancy", "Garcia");
list1.searchByName ("Jamie", "Garcia");
list1.updateNumber ("Nancy", "Garcia", "989-876-1234");
list1.updateNumber ("Jamie", "Garcia", "345-467-1234");
*/
list1.removeRecord ("Mayssaa", "Najjar"); return 0;
}
|