Home > Back-end >  A large white on the list
A large white on the list

Time:09-16

 # include 
#include
#include
using namespace std;
Typedef struct Node
{int data;
Struct Node * next;
} LNode * LinkList;
Void CreateList_L (LinkList & amp; L, int n)
{
int i;
LinkList p;
L=(LinkList) malloc (sizeof (LNode));
L - & gt; Next=NULL;
For (I=n; I> 0; - I)
{
P=(LinkList) malloc (sizeof (LNode));
The scanf (" % d ", & amp; P - & gt; The data);
P - & gt; Next=L - & gt; next; L - & gt; Next=p;
}
}
Int the sum (LinkList & amp; Int L, m, int n)
{

Int I, s=0;
Int a, [20].
for(i=0; i{
L=L - & gt; next;
}
For (I=m; i<=n; I++)
{
A [I - m]=L - & gt; The data;
L=L - & gt; next;
}
return s;
}
Void PrintList (LinkList & amp; L, int x, int y)
{
int i;
for(i=0; i{
L=L - & gt; next;
}
For (I=x; i<=y; I++)
{
Cout<& lt; L - & gt; Data<& lt;" ";
L=L - & gt; next;
}
}
Int main ()
{
Int I, j, n, x=0, y=0, Max=0;
LinkList L=NULL;
Cout<& lt;" Please enter the number "& lt; & lt; Endl;
Cin> n;
CreateList_L (m, n);
for(i=1; i<=n; I++)
{
For (j=I; j<=n; J++)
{
If (sum (L, I, j) & gt; Max)
{
Max=sum (L, I, j);
X=I;
Y=j;
}
}
}
PrintList (L, x, y);
Cout<& lt; Endl;
Cout<& lt;" List and the maximum is: "& lt; & lt; Max<& lt; Endl;
return 0;
}


When debugging in L=L - & gt; next; Access conflict, don't know where there is a problem

CodePudding user response:

Where is you have to look at the next question, debugged createlist function

CodePudding user response:

I only show no statement malloc function here, but I put the two lines to use new application dynamic memory

CodePudding user response:

This mixture of c and c + + code is not a good habit
  • Related