Home > Back-end >  Dynamic array structure help
Dynamic array structure help

Time:10-02

For help,,,, just had a afternoon have a clue, and read online again disorderly into a piece of information,,
Is like that, I want to join in the program a dynamic structure array, but there are old tip pointer errors, monitoring the variable indicates the q - & gt; A [I] CXX0030: error: unable to calculate the value of the expression
Pray god give directions
reference
# include & lt; iostream>
#include
using namespace std;

# define OK 1
# define the ERROR 0
# define NULL 0
10 # define T

Typedef struct LNode {
Int start;//record starting point
Int the end;//record end points
Int * a;
Int num.//int num=0; Record the weight number
Struct LNode * next;
} LNode * LinkList;

//initialize each new node
Void InitLNode (LinkList & amp; L)
{
L - & gt; Start=1;
L - & gt; End=1;
L - & gt; Num=NULL;
L - & gt; Next=NULL;

}

//check input initial point is in line with the requirements, and returns the input the starting point of the
Int InPutS ()
{
Int s;
Int ReInput=1;
While (ReInput==1)
{
Cout & lt; <"Input initial point, please input a non-negative integer:";
cin> s;
If (s<0)
{
Cout<& lt;" This number is not in conformity with the requirements, please input again "& lt; }
The else//s>=0
ReInput=0;
}
Return s;
}//end InPutS

//check if the end point of input meets the requirements, and returned to the input end point
Int InPutE () {
Int e;
Int ReInput=1;
While (ReInput==1)
{
Cout & lt; <"Input termination points, please input a non-negative integer:";
cin> e;
If (e<0)
{
Cout<& lt;" This number is not in conformity with the requirements, please input again "& lt; }
The else//e>=0
ReInput=0;
}
Return e;
}//end InPutE

//check if input weight meets the requirements, and returned to the input weights
Int InPutR ()
{
Int r;
Int ReInput=1;
While (ReInput==1)
{
cin> R;
If (r<1)
{
Cout<& lt;" This number is not in conformity with the requirements, please input again "& lt; }
The else//r<=0
ReInput=0;
}
Return r;
}//end InPutR

//create a list to record the relationship between the weight figure more
Void the Create (LinkList & amp; Int L, k)
{//k is starting to choose parameter
Int I, s, e, r, n=1;//s as the starting point, e as the end point, r is right value
L=new LNode;
LNode * a=new LNode [n] * T;//structure defined in the dynamic array
InitLNode (L);//initialize L node
LinkList p=NULL;
LinkList q=NULL;


P=L;

While (k!=0)
{
System (" CLS ");
Cout<& lt;" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "& lt; Cout<& lt;" * 1. I want to enter a pair of points and the weights between them * "& lt; Cout<& lt;" * 0. I figure has been completed, please help me to find the shortest path * "& lt; Cout<& lt;" * please enter 1 or 0 * "& lt; Cout<& lt;" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "& lt; cin> k;
If (k==1)
{
S=InPutS ();//input starting point and and check if it meets the requirements of
E=InPutE ();//input end points and and check if it meets the requirements of

Sleep (1000);
System (" CLS ");

Q=new LNode;
InitLNode (q);//initialize each newly created node
Cout & lt; & lt;" Please input "& lt; <& lt;" Each edge has a weight not more than 10 "& lt; <& lt;" A weight of positive integer "& lt; <& lt;" Said weight enter the "input - 1 & lt; Q - & gt; Start=s;//input starting point
Q - & gt; End=e;//input end point
For (I=0; I & lt; N * T; I++)
{
Cout<& lt;" Please enter the first "& lt; R=InPutR ();//input weights and check if it meets the requirements of
Q - & gt; A, [I]=r.
Q - & gt; Num=q - & gt; Num + 1;
If (r==1)
{
Cout<& lt;" Point "& lt; break;
}
If (i>=n * T)
N++;
}
P - & gt; Next=q;
P=q;
}//end the if (k==1)
P - & gt; Next=NULL;
Sleep (1000);
}//end while (k!=0)
}//end the Create (LinkList & amp; Int L, k)


//in user input each edge weights for minimum weight, and create and output the minimum weight matrix
Void SelectList (LinkList L, grap b)
{
LinkList p, q;
P=L - & gt; Next;
Int I, j, min, s, e;


While (p!=NULL)
{

Min=p - & gt; A, [0].
For (I=0; I & lt; P - & gt; Num. I++)
{

If (p - & gt; A [I] <=min& & P - & gt; A [I]!=1)
{
Min=p - & gt; A, [I].
}
}
S=p - & gt; The start;
E=p - & gt; The end;
B [s] [e]=min;
P=p - & gt; Next;
}//end while (p!=NULL)

//output minimum weight matrix
Cout<& lt;" Through the analysis, the minimum weight matrix is: "& lt; for(i=0; I<10; I++)
{
for(j=0; J<10; J++)
{
Cout}
Cout}
}//end SelectList (LinkList L, grap b)

//determine whether user input points in the picture
Bool IsInGraph (LinkList & amp; Int L, s, int IsStart)//s is entered by the user find the start or end point of the
//IsStart=1 means to judge is the starting point, IsStart=0 to determine the end point
{
LinkList p;
P=L;
If (IsStart==1)//began to judge whether the starting point of the user input in figure
{
While (p!=NULL)
{
If (s==p - & gt; Start)//specified in figure can find the user input the starting point of the
{
return true;
}
P=p - & gt; Next;
}
return false;//that seek along while also didn't find the user to enter the starting point of the
}
The else
{
While (p!=NULL)
{
If (s==p - & gt; End)//specified in figure can find user input end point of the
{
return true;
}
P=p - & gt; Next;
}
return false;//that seek along while also didn't find the user to enter the end point of the
}


}


Post for the first time, not too familiar with, forgive me
  • Related