#include
using namespace std;
# define MAX 100
# define inf 10000
Int A [MAX] [MAX], visited (MAX), g (MAX);
Typedef int elem_t;
Typedef struct HeapStruct * Minheap;
Struct HeapStruct {
Elem_t H (MAX);//storage pile element array
Elem_t ph (MAX);
Int size;//the number of elements in the heap of current
};
Void Bubbleup (HeapStruct Heap, int n)
{
While (n> 1)
{
If (Heap. H [n]
Int TMP=Heap. H [n];
Heap. H [n]=Heap. H [n/2];
Heap. H [n/2]=TMP;
N=n/2;
}
The else
break;
}
}
Int ExtractMin (HeapStruct Heap)
{
Int M=Heap. H [1];
Int pa, child, temp1;
Temp1=Heap. H [Heap size];
Heap. Size -;
//Heap. H [Heap size]=0;
For (pa=1; Pa * 2 & lt;=Heap. Size; Pa=child)//bubble down
{
The child=2 * pa;
If (Heap. H [child] & gt; Heap. H child + [1] & amp; & Heap. Size> Child + 1)=
Child++;
If (temp1 & gt; Heap. H [child])
Heap. H (pa)=Heap. H [child].
The else
break;
}
Heap. H (pa)=temp1;
Visited [M] [g]=1;// here
Return M;
}
Void Heapinsert (HeapStruct Heap, int n)
{
Heap. H [+ + Heap size]=n;
Bubbleup (Heap, the Heap size);
}
Void prim (int m, int n, int A [MAX] [MAX], int [], p HeapStruct Heap)
{
P [m]=0;
Int temp=m;
Visited [m]=1;
For (int k=1; K<=n; K++)//heap
{
If (A [m] [k]!=0)
{
P=m [k];
G [A [m] [k]]=k;
Heapinsert (Heap, A [m] [k]);
Heap. Ph [k]=Heap. Size;
}
}
M=g [ExtractMin (Heap)];
While (Heap size!=0)
{
Visited [m]=1;
for(int i=1; I<=n; I++)
{
If (A [m] [I]
P=[I] m;
G [A [m] [I]]=I;
Heap. H [Heap. Ph [I]]=[m] A [I];
Bubbleup (Heap, the Heap. Ph [I]);
}
}
M=g [ExtractMin (Heap)];
}
For (int j=1; J<=n; J++)
If (j!=temp)
Cout
}
First - chance exception in project2. Exe: 0 xc0000005: Access Violation.
CodePudding user response:
Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack, namely "the Call Stack" from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, don't understand when double click on the next line, until we can read ,Determine whether cross-border access, can be in after the last element of an array of the corresponding address set read and write data breakpoints, if the address corresponding to other variables interfere with the judgment, can be more declare an array element, and set the read and write data breakpoints on the corresponding address of the more elements,
# include & lt; Time. H>
#include
#include
Int main () {
Int a, b [11].//was b [10], to decide which words of cross-border, intentionally statement for b [11]
Srand ((unsigned int) time (NULL));//press F11 twice, such as yellow right arrow pointing to the bank, the debugging, the new breakpoint, new data breakpoints, address: & amp; B [10], byte count: 4, sure,
While (1) {//press F5, will stop in the following sentence, as a value of 10, b has been modified to corresponding to 0. [10]. One of the four,
B (11) (a=rand () %]=0;
Sleep (100);
B (11) (a=rand () %]=1;
Sleep (100);
B (11) (a=rand () %]=2;
Sleep (100);
B (11) (a=rand () %]=3;
Sleep (100);
B (11) (a=rand () %]=4;
Sleep (100);
}
return 0;
}
CodePudding user response:
When you run the program got a AV (Access Violation) fault, which means that your program is trying to Access a piece of memory is no longer valid, please note that I mentioned are no longer effective, the majority of cases, the mistakes or because you tried to Access a piece of memory has been released, or want to use a haven't create the object pointer,Access array visited offside!
To the code is not even the main function, no comment, how call also don't know, what also have no, how to see
CodePudding user response:
Visited the corresponding array, subscript, etc., has a problem, crossing the lineCodePudding user response:
Int main (){
Memset (g, 0, sizeof (g));
Memset (visited, 0, sizeof (visited));//initialized to 0
Int n, m, p (MAX);
HeapStruct Heap;
Heap. Size=0;
Cout<& lt;" Please enter the number of vertices: ";
cin> n;
for(int i=1; I<=n; I++)
{
Heap. H [I]=inf;
Cout<& lt;" Please input and "& lt; For (int j=1; J<=n; J++)
cin> A, [I] [j].
}
Cout<& lt;" Please input you want to create the starting point of the minimum spanning tree: ";
cin> m;
Prim (m, n, A, p, Heap);
return 0;
}
I'm sorry, but this is the main function
CodePudding user response: