In this project, y ou will be writi ng an object that implements an ordered link
ID: 3576314 • Letter: I
Question
In this project, you will be writing an object that implements an ordered linked list with operator overload support for insertions and deletions. The specification for the list object will be provided upfront and you must design an implementation that supports the provided specification. In addition, you will be given a list of tasks that should be performed.
CIS 221 Programming II C++ Programming Project operator overloaded ordered Linked List object Overview In this assignment, the student will write a C++ program that implements an "Ordered Linked List" object with support for overloaded insertion and deletion operations implemented through an operator overload. When completing this assignment, the student should demonstrate mastery of the following concepts: Elementary Linked Data Structures Advanced Dynamic Memory Managing Multiple Entities on the Heap Software Engineering Design from Provided Object Specification Operator overloading Binary Operators Intermediate Node Insertion Algorithms Assignment In this project, you will be writing an object that implements an ordered linked list with operator overload support for insertions and deletions. The specification for the list object will be provided upfront and you must design an implementation that supports the provided specification. In addition, you will be given a list of tasks that should be performed. Here is the specification for the object that you are to build. When completing this assignment, you must adhere to the interfaces provided in this header when implementing each method You should not modify this file and use all of its components in the most intuitive way possible. Documentation is provided internally that explain what each method should do in the form of coded comments. Operator Overloaded 0rdered Linked List Specification File Author Description: This is the object specification for an "ordered Linked List overloaded operator allows element insertions. overloaded operator allows for deletions PRE-PROCESSOR #pragma once CONSTANTS const int OK const int NOT FOUND const int ERROR MEMORY -1; NODE SPECIFICATION Description: Each linked 00LNode structure contains the information for a single element in the list struct OOLNode int ayloadExplanation / Answer
/*
Following c++ code performs all operations mentioned in problem statement.
Description of each statement or function given in a comment except the given specifications.
*/
#include <stdio.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int OK=1;
const int NOT_FOUND=2;
const int ERROR_MEMORY=-1;
struct OOLNode
{
int payload;
OOLNode* next;
};
class OOList
{
private:
OOLNode* start;
public:
OOList()
{
start=NULL;
}
int getListSize()
{
int count=0;
OOLNode* temp=start;
while(temp!=NULL)
{
count++;
temp=temp->next;
}
return count;
}
int getListSizeInBytes()
{
return (getListSize()*sizeof(OOLNode));
}
int getListElements(int* populateMeWithElements)
{
int count=0;
OOLNode* temp=start;
while(temp!=NULL)
{
populateMeWithElements[count]=temp->payload;
count++;
temp=temp->next;
}
return count;
}
int addElement(int addMe)
{
//Algorithm for inserting an element in list in increasing order.
OOLNode* t=new OOLNode;
t->next=NULL;
t->payload=addMe;
if(start==NULL)
{
start=t;
return OK;
}
else if(start->payload>addMe)
{
t->next=start;
start=t;
return OK;
}
else
{
OOLNode* temp=start->next;
OOLNode* prev=start;
while(temp!=NULL)
{
if(temp->payload>addMe)
{
t->next=temp;
prev->next=t;
break;
}
prev=temp;
temp=temp->next;
}
if(temp==NULL)
prev->next=t;
return OK;
}
return ERROR_MEMORY;
}
int operator+(int addMe)
{
return addElement(addMe);
}
int deleteElement(int deleteMe)
{
//Algorithm for deleting an element in a list in increasing order.
OOLNode* temp=start;
if(start->payload==deleteMe)
{
start=start->next;
delete temp;
return OK;
}
OOLNode* prev=start;
temp=temp->next;
while(temp!=NULL)
{
if(temp->payload==deleteMe)
{
OOLNode* t=temp;
prev->next=temp->next;
delete t;
return OK;
}
prev=temp;
temp=temp->next;
}
return NOT_FOUND;
}
int operator-(int deleteMe)
{
return deleteElement(deleteMe);
}
};
int main()
{
OOList obj;
int n=100; //Suggest take small values
int min=100;
int max=100000;
int res=0;
while(n) //It will take long time since we iterating it 100 times.
{
int len=obj.getListSize();
int* arr=new int[len];
len=obj.getListElements(arr);
for(int i=0;i<len;i++)
cout<<arr[i]<<" ";
cout<<" ";
delete []arr;
int r=min+(rand()%(int)(max-min+1)); //Generating random number between 100 and 100000
//int r=2;
while(r)
{
int addMe=1+(rand()%(int)(100)); //Generating random number between 1 and 100
obj.addElement(addMe);
r--;
}
r=min + (rand() % (int)(max - min + 1));
while(r)
{
int addMe=1+(rand()%(int)(100));
res=obj.operator+(addMe);
r--;
}
//Deleting elements with payload 1 to 50
for(int i=1;i<=50;i++)
res=obj.deleteElement(i);
//Deleting elements with payload 51 to 100
for(int i=51;i<=100;i++)
res=obj.operator-(i);//res=-obj(i);
n--;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.