int Traversal(struct TreeNode* root, int nums){ if (root!=NULL){ nums++; returns=(int *)realloc(returns,nums*sizeof(int)); returns[nums-1]=root->val; nums=Traversal(root->left, nums); nums=Traversal(root->right, nums); } return nums; }
void Traversal(TreeNode* root, int once, int& res) { if(root == NULL) { return; } once = once * 10 + root->val; if(root->left == NULL && root->right == NULL) { //叶子节点 res += once; // 到达叶子节点, 说明一次从root到叶子节点的深度遍历结束 } Traversal(root->left, once, res); Traversal(root->right, once, res); }
BOOL CSTRPath::FindPath(CObject* pObject,VECTOR3 * pSrcPos, VECTOR3 * pDestPos, VECTOR3 * pWayPointBuf, WORD buffCount, BYTE& wWayPointNum, WORD wDepth) { m_wCurDepth = 0; m_wLimiteDepth = wDepth; PreInit(NULL, (int)(pSrcPos->x/50), (int)(pSrcPos->z/50), (int)(pDestPos->x/50), (int)(pDestPos->z/50)); while(GetBestNode()) { if(m_pCurBestNode->cellNumber == m_TargetCellNumber) break; if(m_wLimiteDepth <= m_wCurDepth) break; Traversal(pObject,m_pCurBestNode); } if(!m_pCurBestNode) return FALSE; CalcWayPoint(pWayPointBuf, buffCount, wWayPointNum); return TRUE; }
int main() { LinkList ls; ls = InitList_rear(); Traversal(ls); /* LinkList find; find = GetElem(ls, 3); printf("%d\n", find->data); find = LocateElem(ls, 111); printf("%d\n", find->data); */ InsertNode(ls, 5, 111); Traversal(ls); DeleteNode(ls, 1); Traversal(ls); return 0; }
int main() { expr x = s_node(5, s_node(7, 42)); std::cout << "Before: " << x << "\n"; boost::apply_visitor(Traversal(), x); std::cout << "After: " << x << "\n"; }
int main( int argc, char *agrv[] ) { Node * Head; int location; Head = Set_Link(); printf("Please input the location(after the number) where you want to insert: "); scanf("%d", &location ); Insert( Head, location ); Traversal( Head ); return 0; }
int main( int argc, char *agrv[] ) { Node * Head; int location; Head = Set_Link(); printf("Please input the element location of you want to delete: "); scanf("%d", &location ); char element = Delete( Head, location ); if ( '0' != element ){ printf("The %c was delete.\n", element ); } else { printf("Delete failed, the link is too short."); } Traversal( Head ); return 0; }
int Traversal(int** result, int **columnSizes, struct TreeNode **current, int layer) { if((*columnSizes)[layer] == 0) return layer; int i = 0, j = 0; result[layer+1] = (int*)malloc(sizeof(int)*1000); struct TreeNode **next = (struct TreeNode **)malloc(sizeof(struct TreeNode *)*1000); for(i = 0; i < (*columnSizes)[layer]; i++) { if(current[i]->left != NULL) { result[layer+1][j] = current[i]->left->val; next[j++] = current[i] -> left; } if(current[i]->right != NULL) { result[layer+1][j] = current[i]->right->val; next[j++] = current[i] -> right; } } (*columnSizes)[layer+1] = j; free(current); return Traversal(result, columnSizes, next, layer+1); }
int main() { InitSeqList(); DbubbleSort(R, 10); Traversal(); }
int sumNumbers(TreeNode* root) { vector<int> res; int once = 0, sum = 0; Traversal(root, once, sum); return sum; }
int* preorderTraversal(struct TreeNode* root, int* returnSize) { if(root!=NULL) returns=(int *)malloc(sizeof(int)); (* returnSize)=Traversal(root,0); return returns; }