Home > Back-end >  Help to have read access conflict
Help to have read access conflict

Time:11-06

The header file:
#include
using namespace std;
Template
The class Singlenode
{
Public:
T data;//data domain
Singlenode * next;//pointer field
Singlenode blank nodes ()//construction, but not initialized data domain
{
This - & gt; next=NULL;
}
Singlenode (T data, Singlenode * next=NULL)//structure data node
{this - & gt; data=https://bbs.csdn.net/topics/data;
This - & gt; Next=next;
}
};
The CPP file:
//write classes and member function, the realization of input a group of elements to build a leading the singly linked list of nodes; The list is not descending order;
//delete the values in the decreasing order list for the node of x;
#include
# include "Singlenode1. H"
using namespace std;
Template
Class Singlelinklist//create a singly linked list class
{public:
Singlenode * the head;//the head pointer
Singlelinklist ();//structure empty table
Singlelinklist (int value [], int n);//structure singly linked list
~ Singlelinklist ();
Boolean isempty ();//to empty
Int getlength (); Length//o
Void the sort ();//order
Void deleteelem (int);//delete specific element
Void clearlist ();//to empty list
Void the display ();
};
Template
Singlelinklist : : Singlelinklist ()//structure empty table
{this - & gt; The head=NULL;
}
Template
Singlelinklist : : Singlelinklist (int value [], int n)//construct singly linked list
{the head=NULL;
If (n> 0)
{
The head=new Singlenode (value [0]);
Singlenode * rear=head;//rear is the tail pointer
Int I=1;
while(i{
Rear - & gt; Next=new Singlenode (the value [i++]);
Rear=rear - & gt; next;
}

}
}
Template//destructor
Singlelinklist : : ~ Singlelinklist ()
{clearlist ();
}
Template//to empty
Bool Singlelinklist : : isempty ()
{return head==NULL;
}
Template
Void Singlelinklist : : clearlist ()//clear list
{Singlenode * p=head;
While (p)
{
Singlenode * q=p;
p=p-> next;
delete q;
}
The head=NULL;
}
Template
Int Singlelinklist : : getlength ()//o long
{Singlenode * p=head;
Int I=0;
while(p!=NULL) {
p=p-> next;
i++;
}
Return the I;
}
Template
Void Singlelinklist : : sort ()//not decreasing order
{Singlenode * p=head;
int t;
Singlenode * q;
for(; p; p=p-> Next) {
For (q=p - & gt; next; q; Q=q - & gt; Next)
{if (q - & gt; Data Data)
T=p - & gt; The data, p - & gt; data=https://bbs.csdn.net/topics/q-> data, q -> data=t;
}
}}
Template
Void Singlelinklist : : deleteelem (int x)//delete node
{Singlenode * p=head;
Singlenode * q;
while(p!=NULL) {
If (p - & gt; data=https://bbs.csdn.net/topics/=x) {
Q=p; p=p-> next; delete q;
} the else p=p - & gt; next; }
}
Template
Void Singlelinklist : : the display () {
Singlenode * p=head;
for(; p; p=p-> Next) {
Cout Data<& lt;" ";
}
Cout}
Int main () {
Int n, x;
The int value [100].
Cout<& lt;" Please enter the number list elements: "& lt; Cin> n;
Cout<& lt;" Please input the list element in turn: "& lt; for(int i=0; icin> The value [I];
}
Singlelinklist T1 (value, n);
If (T1) isempty ()) {
Cout<& lt;" The list is empty! End of the program!" Cout<& lt;" List as follows: "& lt; T1. The display ();
Cout<& lt;" List of length: "& lt; T1. Sort ();
Cout<& lt;" Order list is: "& lt; T1. The display ();
Cout<& lt;" Please input value to delete, and we will delete all of equal value, "& lt; Cin> x;
T1. Deleteelem (x);
Cout<& lt;" List as follows: "& lt; T1. The display ();
T1. ~ Singlelinklist ();
return 0;
}
Then access conflict:
Displays an error of 0 XDDDDDDDD
And made a night really couldn't move I was a child, why the code is so cruel
  • Related