Having a problem with the link list program . have failed to resolve.worked over 12 hours but the solution looks pretty disorganised an incoplete, please advise
thanksInline Code Example Here
` #include <iostream>`
#include <stdlib.h>
#include<list>
using namespace std;
class Node
{
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node * getNext() { return nextNode; };
void setNext(Node * nextNode) { this->nextNode = nextNode; };
int object;
int number;
Node * nextNode;
};
class List
{
public:
List();
void add (int addObject);
int get();
bool next();
friend void traverse(List list);
void create();
friend List addNodes(int number);
void split(int c, List list, List largeList, List smallList);// this the prime issue
void differenceList(List listA, List listB,int Num);//this is the prime issue
private:
int number;
int size;
Node * headNode;
Node * currentNode;
Node * lastCurrentNode;
};
/* Constructor */
List::List()
{
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
lastCurrentNode = NULL;
int number=0;
size = 0;
}
void List::create()// this is the bad way out to get some output, and some manipulation of loop to get result of spliting
//which does not allow user to select a piviot point it just cuts it in half and if list is 21 then there is a problem
//more over the input to split is not from the size of list but just users visual observation
{
List mylist;
int Num;
cout<<"Please enter the value for this list";
cin>>Num;
for(int i=1; i<= Num; i++){ int j; for(j=0; j< i; j++) { if(i%2!=0) {mylist.add(i); break; }}
// Check if loop ended in normal way or by break statement
// Print No
if (i == j) { cout <<"["<< i << "] "; }}
traverse(mylist);
cout<<"Please select the piviot point of your list";
int piv;
cin>>piv;
if(Num>Num/2||Num<Num/2) {cout<<"the value of the piviot shoule be exactly half of the List Node size";
cout<<"Please select the piviot point of your list";
cin>>Num; }
List hislist;
List ob;
for(int i=1; i<=Num/2; i++) { int j; for(j=0; j< i; j++) { if(i%2!=0) { hislist.add(i); break; } }
// Check if loop ended in normal way or by break statement
if (i == j) { cout <<"["<< i << "] "; }} traverse(hislist);
List emlist;
for(int i=1; i<=Num/2 ; i++)
{
int j;
for(j=0; j< i; j++)
{
if(i%2!=0) // If not prime break loop
{
emlist.add(i);
break;
}
}
if (i == j) // Check if loop ended in normal way or by break statement
{
cout <<"["<< i << "] "; // Print No
}}
traverse(emlist);
}
/* add() class method */
void List::add (int addObject)
{
Node * newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL )
{
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else
{
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size ++;
}
/* get() class method */
int List::get()
{
if (currentNode != NULL)
return currentNode->get();
}
/* next() class method */
bool List::next()
{
if (currentNode == NULL) return false;
lastCurrentNode = currentNode;
currentNode = currentNode->getNext();
if (currentNode == NULL || size == 0)
return false;
else
return true;
}
/* Friend function to traverse linked list */
void traverse(List list)
{
Node* savedCurrentNode = list.currentNode;
list.currentNode = list.headNode;
cout << "\n\n Elements of list are given below ";
for(int i = 1; list.next(); i++)
{
cout << "\n Element " << i << " " << list.get();
}
cout << "\n List size = " << list.size <<'\n';
int *ptr;
ptr=&list.size;
list.currentNode = savedCurrentNode;
}
void List:: split(int c, List list, List largeList, List smallList) { }
void List:: differenceList(List listA, List listB, int Num){
cout<<"Please enter the data in ListA";//not working at all
cin>>Num;
for(int i=1; i<=Num/2; i++)
{int j;
for(j=0; j< i; j++)
{
if(i%2!=0) // If not prime break loop
{
listA.add(i);
break;
}
}
if (i == j) // Check if loop ended in normal way or by break statement
{
cout <<"["<< i << "] "; // Print No
}}
traverse(listA);
cout<<"Please eneter the data for List B";
listB;
for(int i=1; i<=Num/2 ; i++)
{
int j;
for(j=0; j< i; j++)
{
if(i%2!=0) // If not prime break loop
{
listB.add(i);
break;
}
}
if (i == j) // Check if loop ended in normal way or by break statement
{
cout <<"["<< i << "] "; // Print No
}}
traverse(listB);
}
int main()
{
cout<<"\n \n********this program is about functions*********\n of singly linked list\n \n";
cout<<"Manu of the program:\n(1) for creating a list of Odd numbers";
cout<<"\n(2) for spliting the List \n(3 for finding the set difference\n \n";
List mylist;
List hislist;
int choice;
cin>>choice;
switch (choice)//switch failed
{
case 1:
mylist. create();
break;
case 2:
mylist.create();
hislist.create();
break;
case 3:
cout<<"case 3";
List ob ;
List oc;
ob.create();
ob.create();
//oc.create();
break;
}
}
//