I wrote a * pathfinding use I want to make it round on each loop creates a node does not cover the create Int c=1, * p, path [MAXSIZE * 2]; Int minf minnum;//the point of minimum cost and number The Open OList.//pending node InitOpen (& amp; OList);//initialize the backlog node table The Node startNode; CreateNode (& amp; StartNode, s.x, s.y, NULL, s, f);//create a starting point node The map [s.x] [s.y]. Pass=1; The Node nowNode=startNode; While (1) { If (CanGo (nowNode. X - 1, nowNode. J y, map)) {// Node newNode; The Node curNode; CurNode=nowNode; CreateNode (& amp; NewNode, nowNode nowNode. J y, x - 1, & amp; CurNode, s, f); AddOpen (& amp; OList, & amp; NewNode); } If (CanGo (nowNode. X + 1, nowNode. J y, map)) {// Node newNode; The Node curNode; CurNode=nowNode; CreateNode (& amp; NewNode, nowNode. X + 1, nowNode. J y, & amp; CurNode, s, f); AddOpen (& amp; OList, & amp; NewNode); } If (CanGo (nowNode. X, nowNode. Y 1, map)) {//left Node newNode; The Node curNode; CurNode=nowNode; CreateNode (& amp; NewNode, nowNode. X, nowNode. Y 1, & amp; CurNode, s, f); AddOpen (& amp; OList, & amp; NewNode); } If (CanGo (nowNode. X, nowNode. Y + 1, map)) {//right Node newNode; The Node curNode; CurNode=nowNode; CreateNode (& amp; NewNode, nowNode. X, nowNode. Y + 1, & amp; CurNode, s, f); AddOpen (& amp; OList, & amp; NewNode); } If (OList. Length==0) { The path [0]=0; P=& amp; The path; return p; } The else { for(int i=0; i If (map [OList NodeList [I] - & gt; x] [OList. The NodeList [I] - & gt; y]. Pass==1) { MinusOpen (& amp; OList, I); I -; } } Minf=OList. NodeList [0] - & gt; f; Minnum=0; for(int i=1; i If (minf> OList. NodeList [I] - & gt; F) { Minf=OList. NodeList [I] - & gt; f; Minnum=I; } } Node newNode; The Node curNode; CurNode=nowNode; CreateNode (& amp; NewNode, OList. NodeList [minnum] - & gt; X, OList. NodeList [minnum] - & gt; Y, & amp; CurNode, s, f); NowNode=newNode; The map [OList NodeList [minnum] - & gt; x] [OList. The NodeList [minnum] - & gt; y]. Pass=1; MinusOpen (& amp; OList minnum); } If (nowNode. X==f.x & amp; & NowNode. Y=={f.y) Node * pathNode;//back path PathNode=& amp; NowNode; While (pathNode!=NULL) { The path/c + +=pathNode - & gt; x; The path/c + +=pathNode - & gt; y; PathNode=pathNode - & gt; The Parent; } The path [0]=c - 1; P=& amp; The path; return p; } } CodePudding user response:
Local variables occupy memory stack area, block during process execution will allocate and release in time, Stack memory to low expansion, so when the block executes, will extend from the top address to low several bytes address range, This address range will be linked to a physical memory mapping, Blocks of all the parameters in a local variable, the return value, etc exist in the area, This address range of the low address is this statement solid block of memory, also is the new stack address, The local variables of address range is the whole address, an interval of a small piece of a small piece of corresponding physical memory, When the block has been completed, the stack area of memory is released, the stack back to address before stack, So, in theory, with the level of address blocks must be based on the same stack to allocate memory, low So the address of the local variables of them, which may be repetitive, but their corresponding physical memory does not repeat, This question doesn't make any sense! CodePudding user response:
The expanding its scope, and don't define local variables (for), consider using node array, so don't create every time, CodePudding user response:
Change CreateNode