本文整理汇总了C++中printPath函数的典型用法代码示例。如果您正苦于以下问题:C++ printPath函数的具体用法?C++ printPath怎么用?C++ printPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了printPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printPath
void printPath(TreeNode* root, TreeNode* target_leaf){
if (root == NULL)
return NULL;
if (root == target_leaf || printPath(root->left, target_leaf) || printPath(root->right, target_leaf)){
printf ("%d", root->data);
return true;
}
return false;
}
示例2: switch
void Magnusson::insertSwapArcsForNewUsedPath(TrackingAlgorithm::Path &p)
{
/* Swap Arc Insertion: walk along path
* - find alternative incoming arcs of the traversed node, where there are also multiple outgoing arcs of the previous node
* - insert swap arc between any alternative pair of nodes connected to the path by in / out arcs.
*/
for(Path::iterator it = p.begin(); it != p.end(); ++it)
{
switch((*it)->getType())
{
// do not add swap arcs for division or dummy
case Arc::Division:
case Arc::Dummy:
break;
case Arc::Move:
insertMoveSwapArcs(*it);
break;
case Arc::Appearance:
insertAppearanceSwapArcs(*it);
break;
case Arc::Disappearance:
insertDisappearanceSwapArcs(*it);
break;
case Arc::Swap:
{
printPath(p);
throw std::runtime_error("There should not be swap arcs left after cleaning up the path");
}
}
}
}
示例3: main
int main(int argc, char *argv[]) {
int i, j,k;
int u, v, w;
FILE *fin = fopen("./tmp/graph", "r");
fscanf(fin, "%d", &e);
for (i = 0; i < e; ++i)
for (j = 0; j < e; ++j)
dist[i][j] = 0;
n = -1;
for (i = 0; i < e; ++i) {
fscanf(fin, "%d%d%d", &u, &v, &w);
dist[u][v] = w;
dist[v][u] = w;
n = MAX(u, MAX(v, n));
}
fclose(fin);
for(k=1 ; k <= n;k++){
dijkstra(k);
for (i = 1; i <= n; ++i) {
dst=i;
if(k==i)
continue;
printPath(i,dst);
dst =0;
}
}
return 0;
}
示例4: main
int main() {
while (scanf("%d%d", &total_length, &track_number) != EOF) {
for (int i = 1; i <= track_number; i++) {
scanf("%d", &track[i]);
}
memset(dp, 0, sizeof(dp));
memset(pre, -1, sizeof(pre));
dp[0] = 1;
for (int i = 1; i <= track_number; i++) {
for (int j = total_length; j >= track[i]; j--) {
if (dp[j - track[i]] == 1) {
dp[j] = 1;
if (pre[j] == -1) {
pre[j] = i;
}
}
}
}
int i;
for (i = total_length; i >= 1; i--) {
if (dp[i] == 1) {
break;
}
}
printPath(i);
printf("sum:%d\n", i);
}
return 0;
}
示例5: main
int main(int argc,char* argv[]){
printPath(".");
printf("\n");
exit(1);
}
示例6: testGetCurrentCycle
void testGetCurrentCycle() {
uint8_t array[] = {3, 1, 3, 1, 2, 3};
uint8_t clockSize = 6;
printf("\n====================\n");
printf("get current cycle\n");
printf("====================\n");
printf("new test with: ");
printClock(array, clockSize);
SearchTreeNode *stn1 = newSearchTreeNode(NULL, array + 1);
SearchTreeNode *stn0 = newSearchTreeNode(stn1, array);
SearchTreeNode *stn3 = newSearchTreeNode(stn0, array + 3);
SearchTreeNode *stn4 = newSearchTreeNode(stn3, array + 4);
SearchTreeNode *stn2 = newSearchTreeNode(stn4, array + 2);
SearchTreeNode *stn5 = newSearchTreeNode(stn2, array + 5);
GArray * path = getCurrentPath(stn5);
printf("assert that path has the length of the clock\n");
assert(path->len == clockSize);
SearchTreeNode *pathnode = &g_array_index(path, SearchTreeNode, 0);
printf("assert that the first element of the path is stn1\n");
assert(stn1->content == pathnode->content);
pathnode = &g_array_index(path, SearchTreeNode, clockSize - 1);
printf("assert that the last element of the path is stn5\n");
assert(stn5->content == pathnode->content);
printPath(path, array);
printf("add stn1 as child of stn5 (create contradiction)\n");
SearchTreeNode *stnLast = newSearchTreeNode(stn5, array + 1);
printf("assert that contradicted path is null\n");
path = getCurrentPath(stnLast);
assert(path == NULL);
printf("assert that incomplete path is not null\n");
path = getCurrentPath(stn4);
assert(path != NULL && path->len < clockSize);
}
示例7: main
int main()
{
int n,i,j;
printf("\nEnter the number of total Node in Graph:");
scanf("\n%d",&n) ;
printf("\nEnter the distance between vertices.....\nIf no edge put 99(say infinity):\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("\nEnter value for Graph[%d][%d]:",i,j);
scanf("%d",&graph[i][j]);
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
path[i][j]=-1;
else
path[i][j]=i;
}
}
display(graph,n);
floydWarshall(graph,n);
printf("\nAfter Algo Appiled: \n");
display(graph,n);
printPath(path,n);
printf("\nPath Without Recursion:\n");
printPathWithoutRecursive(path,n);
return 0;
}
示例8: Dijkstra
void Dijkstra(MGraph* G, int v) {
int min_d, u, i, j;
for (i = 0; i < G->n; i++) {
s[i] = 0;
d[i] = G->E[v][i];
path[i] = (d[i] < INFI) ? v : -1;
}
s[v] = 1;
for (i = 0; i < G->n; i++) {
min_d = INFI;
for (j = 0; j < G->n; j++)
if (s[j] == 0 && d[j] < min_d)
{ min_d = d[j]; u = j; }
s[u] = 1;
for (j = 0; j < G->n; j++) {
if (d[u] + G->E[u][j] < d[j]) {
d[j] = d[u] + G->E[u][j];
path[j] = u;
}
}
}
printPath(G, v);
}
示例9: main
int main(int argc, char *argv[]) {
int i, j;
int u, v, w;
FILE *fin = fopen("dist.txt", "r");
fscanf(fin, "%d", &e);
for (i = 0; i < e; ++i)
for (j = 0; j < e; ++j)
dist[i][j] = 0;
n = -1;
for (i = 0; i < e; ++i) {
fscanf(fin, "%d%d%d", &u, &v, &w);
dist[u][v] = w;
n = MAX(u, MAX(v, n));
}
fclose(fin);
dijkstra(1);
printD();
printf("\n");
for (i = 1; i <= n; ++i) {
printf("Path to %d: ", i);
printPath(i);
printf("\n");
}
return 0;
}
示例10: printDTree
void printDTree(dTree* node, int depth) {
dTree* current = node;
if (depth==0){
printf("root is %i\n", current->index);
}
printf("\n");
for(int i =0; i< depth; i++){
printf("\t");
}
printf("Node index: %i\n", current->index);
for(int i =0; i< depth; i++){
printf("\t");
}
printf("Node maxOverlap %i\n", current->overlap);
for(int i =0; i< depth; i++){
printf("\t");
}
printf("Node totalOverlap %i\n", current->totalOverlap);
for(int i =0; i< depth; i++){
printf("\t");
}
depth++;
if(current->path != NULL){
printPath(current->path);
}
if(current->xTraversal != NULL){
printDTree(current->xTraversal, depth);
}
if(current->yTraversal != NULL){
printDTree(current->yTraversal, depth);
}
}
示例11: WriteExtendedFileExtensionInfo
// cf. http://msdn.microsoft.com/en-us/library/cc144148(v=vs.85).aspx
static bool WriteExtendedFileExtensionInfo(HKEY hkey)
{
bool success = true;
ScopedMem<WCHAR> exePath(GetInstalledExePath());
if (HKEY_LOCAL_MACHINE == hkey)
success &= WriteRegStr(hkey, L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" EXENAME, NULL, exePath);
// mirroring some of what DoAssociateExeWithPdfExtension() does (cf. AppTools.cpp)
ScopedMem<WCHAR> iconPath(str::Join(exePath, L",1"));
success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\DefaultIcon", NULL, iconPath);
ScopedMem<WCHAR> cmdPath(str::Format(L"\"%s\" \"%%1\" %%*", exePath));
success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Open\\Command", NULL, cmdPath);
ScopedMem<WCHAR> printPath(str::Format(L"\"%s\" -print-to-default \"%%1\"", exePath));
success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\Print\\Command", NULL, printPath);
ScopedMem<WCHAR> printToPath(str::Format(L"\"%s\" -print-to \"%%2\" \"%%1\"", exePath));
success &= WriteRegStr(hkey, REG_CLASSES_APPS L"\\Shell\\PrintTo\\Command", NULL, printToPath);
// don't add REG_CLASSES_APPS L"\\SupportedTypes", as that prevents SumatraPDF.exe to
// potentially appear in the Open With lists for other filetypes (such as single images)
// add the installed SumatraPDF.exe to the Open With lists of the supported file extensions
for (int i = 0; NULL != gSupportedExts[i]; i++) {
ScopedMem<WCHAR> keyname(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" EXENAME));
success &= CreateRegKey(hkey, keyname);
// TODO: stop removing this after version 1.8 (was wrongly created for version 1.6)
keyname.Set(str::Join(L"Software\\Classes\\", gSupportedExts[i], L"\\OpenWithList\\" APP_NAME_STR));
DeleteRegKey(hkey, keyname);
}
// in case these values don't exist yet (we won't delete these at uninstallation)
success &= WriteRegStr(hkey, REG_CLASSES_PDF, L"Content Type", L"application/pdf");
success &= WriteRegStr(hkey, L"Software\\Classes\\MIME\\Database\\Content Type\\application/pdf", L"Extension", L".pdf");
return success;
}
示例12: main
int main(void){
FILE *fp = fopen("input.txt","r");
if(fp == NULL){
printf("No file found.\n");
for(;;);
}
qBack = (queueElement **)malloc(sizeof(queueElement **));
qFront = (queueElement **)malloc(sizeof(queueElement **));
(*qBack) = NULL;
(*qFront)= NULL;
int nextInt;
bool currentAr[BOARDSIZE];
unsigned short firstBoard;
int i;
for (i = 0; i < BOARDSIZE; i++) *(currentAr + i) = false;
nextInt = readNextInt(fp);
initializeArray(nextInt, currentAr, fp);
firstBoard=boolToShort(currentAr);
parent[firstBoard] = firstBoard;
hitPosition[firstBoard] = 0;
for (i = 0; i < BOARDSIZE;i++)
board[firstBoard][i] = currentAr[i];
unsigned short emptyBoard = bfs(firstBoard);
printf("done bfs, empty board is board number: %d, first board: %d\n", emptyBoard, firstBoard);
printPath(emptyBoard, firstBoard);
fclose(fp);
return 0;
}
示例13: printPath
bool ShaderBuild::parse(std::string file, FileBits& sourceBits, Defines& defs, std::vector<std::string> path)
{
int fileBitStart = (int)sourceBits.size();
//maintain include stack
path.push_back(file);
//detect infinite include
for (int i = (int)path.size() - 1; i >= 0; --i)
{
int f = (int)path[i].find(":");
if (f > 0 && path[i].substr(0,f) == file)
{
std::cout << printPath(path);
std::cout << "Error: " << "Include loop" << ": " << file << std::endl;
return false;
}
}
//if the file has already been parsed, simply append the references to the bits we already have
//don't add to the cache if #defines haven't been injected yet
if (!firstContentLine && parseCache.find(file) != parseCache.end())
{
sourceBits.insert(sourceBits.end(), parseCache[file].begin(), parseCache[file].end());
return true;
}
//buffer from memory or file
std::streambuf* ifileBuff;
//check if the source has already been supplied
std::map<std::string, const char*>::iterator override;
override = includeOverrides.find(file);
示例14: main
int main(void) {
int i, j;
int found_src, found_dest;
char src_name[MAXNAME + 1];
char dest_name[MAXNAME + 1];
int distance;
while (scanf("%s to %s = %d", src_name, dest_name, &distance) != EOF) {
found_src = found_dest = 0;
min_distance += distance;
for (i = 0; i < size; i++) {
if (!strcmp(src_name, locations[i].name)) {
found_src = 1;
break;
}
}
for (j = 0; j < size; j++) {
if (!strcmp(dest_name, locations[j].name)) {
found_dest = 1;
break;
}
}
if (!found_src) {
i = newLocation(src_name);
}
if (!found_dest) {
j = newLocation(dest_name);
}
addConnection(&locations[i], &locations[j], distance);
}
for(i = 0; i < size; i++)
tryPath(locations + i, 0, 0);
printf("Minimum path: %d\n", min_distance);
printPath(min_path, size);
printf("Maximum path: %d\n", max_distance);
printPath(max_path, size);
return 0;
}
示例15: printPath
// A utility function that prints all nodes on the path from root to target_leaf
bool printPath (struct node *root, struct node *target_leaf)
{
// base case
if (root == NULL)
return false;
// return true if this node is the target_leaf or target leaf is present in
// one of its descendants
if (root == target_leaf || printPath(root->left, target_leaf) ||
printPath(root->right, target_leaf) )
{
printf("%d ", root->data);
return true;
}
return false;
}