#include<iostream>
#include<string.h>
using namespace std;
//Class Passenger
class Passenger
{
public:
string Name;
int ID;
string contactInfo;
string bookingRef;
public:
// Setter
void setName(string Name) {
this->Name = Name;
}
void setID(int ID) {
this->ID = ID;
}
void setContactInfo(string contactInfo) {
this->contactInfo = contactInfo;
}
void setBookingRef(string bookingRef) {
this->bookingRef = bookingRef;
}
// Getter
string getName() {
return Name;
}
int getID() {
return ID;
}
string getContactInfo() {
return contactInfo;
}
string getBookingRef() {
return bookingRef;
}
void display(){
}
};
//Class City
class City
{
public:
string Name;
string cityCode;
string countryCode;
public:
// Setter
void setName(string Name) {
this->Name = Name;
}
void setCityCode(string cityCode) {
this->cityCode = cityCode;
}
void setCountryCode(string countryCode) {
this->countryCode = countryCode;
}
// Getter
string getName() {
return Name;
}
string getCityCode() {
return cityCode;
}
string getCountryCode() {
return countryCode;
}
void display(){
}
};
// Node class to represent
// a node of the linked list.
class Node {
public:
public:
double data; // data
Node* next; // pointer to next
};
// Linked list class to
// implement a linked list.
class List {
public:
List(void) { head = NULL; } // constructor
~List(void); // destructor
bool IsEmpty() { return head == NULL; }
Node* InsertNode(int index, double x);
int FindNode(double x);
int DeleteNode(double x);
void DisplayList(void);
private:
Node* head;
};
Node* List::InsertNode(int index, double x) {
if (index < 0) return NULL;
int currIndex = 1;
Node* currNode = head;
while (currNode && index > currIndex) {
currNode = currNode->next;
currIndex++;
}
if (index > 0 && currNode == NULL) return NULL;
Node* newNode = new Node;
newNode->data = x;
if (index == 0) {
newNode->next = head;
head = newNode;
}
else {
newNode->next = currNode->next;
currNode->next = newNode;
}
return newNode;
}
int List::FindNode(double x) {
Node* currNode = head;
int currIndex = 1;
while (currNode && currNode->data != x) {
currNode = currNode->next;
currIndex++;
}
if (currNode) return currIndex;
return 0;
}
int List::DeleteNode(double x) {
Node* prevNode = NULL;
Node* currNode = head;
int currIndex = 1;
while (currNode && currNode->data != x) {
prevNode = currNode;
currNode = currNode->next;
currIndex++;
}
if (currNode) {
if (prevNode) {
prevNode->next = currNode->next;
delete currNode;
}
else {
head = currNode->next;
delete currNode;
}
return currIndex;
}
return 0;
}
void List::DisplayList()
{
int num = 0;
Node* currNode = head;
while (currNode != NULL){
cout << currNode->data << endl;
currNode = currNode->next;
num++;
}
cout << "Number of nodes in the list: " << num << endl;
}
int main()
{
List list;
list.InsertNode(0, 7.0); // successful
list.DisplayList();
if(list.FindNode(5.0) > 0) cout << "5.0 found" << endl;
list.DeleteNode(7.0);
list.DisplayList();
return 0;
}