Professional Documents
Culture Documents
Lab.14.oop - Syed Mujtaba Ali Shah.22i-6176.c
Lab.14.oop - Syed Mujtaba Ali Shah.22i-6176.c
Lab.14.oop - Syed Mujtaba Ali Shah.22i-6176.c
#include <iostream>
using namespace std;
struct nodeType{
int info;
nodeType *link;
};
class linklist{
nodeType *head;
public:
linklist() { head = NULL; }
~linklist();
void displayList();
void AddatFront(int);
void AddatEnd(int);
void deleteValue(int val);
void deleteFirst();
bool operator==(const linklist& otherList);
void operator+=(const linklist& otherList); // declaration of the
overloaded operator+=
};
void linklist::deleteFirst(){
nodeType *d = head;
head = head->link;
delete d;
}
void linklist::displayList(){
nodeType *curr = head;
while(curr!=NULL){
cout<<curr->info<<" ";
curr=curr->link;
}
cout<<endl;
}
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
nodeType* ptr1 = new nodeType;
ptr1->info=x;
ptr1->link=NULL;
ptr->link=ptr1;
linklist::~linklist() {
nodeType* del = head;
while (del != NULL) {
nodeType* next = del->link;
delete del;
del = next;
}
head = NULL;
}
#include "LAB_14.h"
int main() {
linklist list1;
list1.AddatFront(44);
list1.AddatFront(23);
list1.AddatFront(65);
list1.AddatFront(10);
list1.displayList();
list1.deleteValue(44);
list1.displayList();
list1.deleteFirst();
list1.displayList();
linklist list2;
list2.AddatFront(500);
list2.AddatFront(400);
list2.AddatEnd(300);
list2.displayList();
if (list1 == list2) {
cout << "The two linked lists are identical." << endl;
} else {
cout << "The two linked lists are not identical." << endl;
}
return 0;
}