headers.h
DESCRIPTION
header ,,, hodd hujiji nkoneTRANSCRIPT
-
/*
This file contains the class defination. The Member functions declared here are defined in separate
files, the member functions for
performing various tasks for LINKED LIST unsing arrays is defined in file- using array.cpp And in same
way member functions for implementation
of Linked List using Pointers is defined in file-pointers.cpp.
Constructor as well as destructor are defined below.
Constructor initializes the Private data member "requestedSize".
Destructor deallocates the dynamic memory which is done in main.cpp.
****************Author: Navjot Singh, Chinmayi, Daamanmeet,
Srini********************************************
*/
#define maxArraysize 50000 // this is maximum size that user can request to create the Linked List
#include
#include
#include
#include
#include
using namespace std;
class helloArray
-
{
private:
struct node
{
int data;
node *next;
};
int requestedSize; //requestedSize will change on calling the operation ADD,
DELETE node.
int array[maxArraysize]; // to implement Linked List using array, we are using
array[maxArraysize].
node *head=NULL;
public:
helloArray(int mSize) // Constructor is
called on creating the object. And required size of Linked List is passed as parameter.
{
requestedSize=mSize;
}
~helloArray() //Destructor
{
coutnext;
delete head;
head=ptr;
}
-
}
// Member function starting with 'p' does operation related to pointers.
void p_init_data();
void p_display_data();
int p_insertNode(int, int);
int p_deleteNode(int);
void p_searchValue(int);
void p_nextNode(int);
int check_size(int);
int returnLength();
int& operator[](const int mIndex); // Index operator overloading is used for filling the array
elements.
// Member functions for various operation for linked list using arrays.
int insertNode(int, int);
int deleteNode(int);
void searchValue(int);
void display_data();
void nextNode(int);
void change_reqSize(char mAction) // This function changes the size of requestedSize on
addition as well as deletion of any element.
{
cout
-
else if(mAction == 'D')
requestedSize --;
}
int operator=(helloArray &obj1) // Assignment operator overloading. getting called in case 8
from main.cpp
{
this->requestedSize=obj1.requestedSize;
//initializing array..
for(int i=0;irequestedSize;i++)
{
this->array[i]=obj1.array[i];
//cout
-
this->head=new node;
node *new_ptr=this->head;
node *cond= obj1.head;
int i=0;
while(i < this->requestedSize)
{
new_ptr -> data= cond->data;
new_ptr->next=new node;
int j=i+1;
if (j == requestedSize)
break;
new_ptr=new_ptr->next;
cond=cond->next;
i++;
}
new_ptr->next=NULL;
}
};