Home > Back-end >  To determine whether a linked list in ascending order
To determine whether a linked list in ascending order

Time:10-19

#include
using namespace std;
Struct Node {
Double a;
Node * next;
The Node (int x) : a (x), next (NULL) {}
};
Bool isInOrder (Node * first) {
Node * p=first;
If (p==NULL) return false.
while (p !=NULL) {
If (p - & gt; A. & gt; P - & gt; Next - & gt; A) return false.
P=p - & gt; Next;
}
return true;
}
Int main () {
int n;
Double m;
Cout & lt; <"Both please input the number of data:";
Cin & gt; & gt; n;
Cout & lt; <"Both please input the data:";
First Node * and * p, * f;
F=new Node (0);
The first=f;
for (int i=0; I & lt; n; I++) {
Cin & gt;> m;
P=new Node (m);
F - & gt; Next=p;
F=p;
}
The first=first - & gt; Next;
If (isInOrder (first)==true) cout & lt; <"This listnode is in right order./n";
The else cout & lt; <"This listnode is not in right order./n";
}

CodePudding user response:

Look, what is going wrong, the is not ascending can normal output, is not ascending, prompt the if (p - & gt; A. & gt; P - & gt; Next - & gt; A) return false. The 0 x00d6266b (located in Project1. Exe) caused by abnormal: 0 xc0000005: access conflict while reading position 0 x00000000, true don't know how to do, also check on the Internet a lot of solution, is not make!
Prev:linkage
Next:C
  • Related