okay so I corrected the code
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
class Node{
public:
int value;
Node *next;
};
class LinkedList{ //Singly Linked List
public:
LinkedList(){
head=NULL;
}
void SubMain(){
bool result;
UniqueRandomData(10);
CallInsertNode();
PrintNode();
result=CheckNode();
CallDeleteNode();
}
void UniqueRandomData(int n){
int i, j, k, temp;
this->n=n;
x=new int[n];
for(i=0; i<n; i++)
x[i]=(i+1)*10;
for(i=0; i<n; i++){
j=rand()%n;
k=rand()%n;
temp=x[j];
x[j]=x[k];
x[k]=temp;
}
for(i=0; i<n; i++)
cout<<x[i]<<" ";
cout<<endl;
}
void InsertNode(int v){
cout<<v<<" is inserted"<<endl;
Node *cur=head;//cur=head
Node* node=new Node();//new Node
while(cur!=NULL){
Node *prev=cur;
cur=cur->next;
if(node>prev && node<cur)
cur=prev->next;
else if(node<prev){
prev=node;
cur=prev;
}
}
}
void PrintNode(){
Node *cur=head;
while(cur!=0){
cout<<cur->value<<" ";
cur=cur->next;
}
cout<<endl;
}
void CallInsertNode(){
int i;
for(i=0; i<n; i++)
InsertNode(x[i]);
}
bool CheckNode(){
Node *cur=head;
while(cur !=NULL && cur->next !=NULL)
if(cur->value > cur->next->value){
cout<<"Error!"<<endl;
cout<<cur->value<<", "<<cur->next->value<<endl;
return false;
}
else
cur=cur->next;
cout<<"Good job!"<<endl;
return true;
}
void CallDeleteNode(){
int i;
for(i=0; i<n; i++){
DeleteNode(x[i]);
this->PrintNode();
}
}
void DeleteNode(int v){
cout<<v<<" is deleted."<<endl;
Node *cur=head;
Node *delNode=cur;
while(cur!=NULL)
find(cur, delNode, );
cur=cur->next;
delete delNode;
}
private:
Node *head;
int *x;
int n;
};
int main(){
LinkedList a;
a.SubMain();
return 0;
system("pause");
}
I fixed the codes for void InsertNode(int v) and void DeleteNode(int v) since these are the ones I have to solve and I don't know what to do with the find() in the void deleteNode(int v) btw.