int main(void) { Node *head = NULL, *tail = NULL; int i; for(i = 0; i < 10; i++) { append(createNode(10-i), &head, &tail); } insertAt(11, &head, &tail, 5); insertAt(12, &head, &tail, 0); insertAt(13, &head, &tail, 15); insertAt(15, &head, &tail, 8); insertAt(16, &head, &tail, 7); sortedInsert(14, &head, &tail); printNodes(head); printf("\nThere are %d Nodes in this linked list.\n\n\n", count(head)); sort(&head, &tail); printNodes(head); printf("\nThere are %d Nodes in this linked list.\n\n", count(head)); return 0; }
// traverse a binary search tree // in order, printing the values // found at each node void printNodes( NodePointer np ) { if( np != NULL ) { printNodes( (*np).lp ); printf("value at node = %4d\n", (*np).value ); printNodes( (*np).rp ); } // endif } // printNodes
void printNodes(Node* node) { if (node == NULL) return; float3 location = *node->location; printf("(%f, %f, %f)\n", location.x, location.y, location.z); printNodes(node->left); printNodes(node->right); }
int main() { auto gHeap = new cs6771::Graph<std::string,int>{}; // add this data into the graph gHeap->addNode("a"); gHeap->addNode("b"); gHeap->addNode("c"); gHeap->addNode("d"); gHeap->addEdge("b","a",3); gHeap->addEdge("b","a",5); gHeap->addEdge("c","a",3); std::cout << "original graph" << std::endl; gHeap->printNodes(); gHeap->printEdges("b"); cs6771::Graph<std::string,int> gHeapCopy; gHeapCopy.addNode("z"); std::cout << "Graph before copy assignment" << std::endl; gHeapCopy.printNodes(); gHeapCopy = *gHeap; // copy assignment gHeap->deleteNode("a"); std::cout << "original graph after delete" << std::endl; gHeap->printNodes(); gHeap->printEdges("b"); std::cout << "copied graph after delete in other graph" << std::endl; gHeapCopy.printNodes(); gHeapCopy.printEdges("b"); delete gHeap; std::cout << "copied graph after other graph is deleted" << std::endl; gHeapCopy.printNodes(); }
//traverses a BST in order, printing the values found at each node void printNodes (NodePointer np){ if( np != NULL){ printNodes ( np->lp ); printf("value at node = %4d\n", np->value); printNodes( np->rp ) ; }//if }//printNodes(NodePointer np)
/* Print all SNodes in a Sarq */ static void printNodes(FILE * stream, SarqNode root, SarqType * type) { if ((root) == NULL) { fprintf(stream, "-"); return; } fprintf(stream, " ("); type->print(stream, root->item); fprintf(stream, " "); printNodes(stream, root->left, type); fprintf(stream, " "); printNodes(stream, root->right, type); fprintf(stream, ") "); }
// Pretty formatting of a binary tree to the output stream // @ param // level Control how wide you want the tree to sparse (eg, level 1 has the minimum space between nodes, while level 2 has a larger space between nodes) // indentSpace Change this to add some indent space to the left (eg, indentSpace of 0 means the lowest level of the left node will stick to the left margin) void printPretty(BinaryTree *root, int level, int indentSpace, ostream& out) { int h = maxHeight(root); int nodesInThisLevel = 1; int branchLen = 2 * ((int)pow(2.0, h) - 1) - (3 - level)*(int)pow(2.0, h - 1); // eq of the length of branch for each node of each level int nodeSpaceLen = 2 + (level + 1)*(int)pow(2.0, h); // distance between left neighbor node's right arm and right neighbor node's left arm int startLen = branchLen + (3 - level) + indentSpace; // starting space to the first node to print of each level (for the left most node of each level only) deque<BinaryTree*> nodesQueue; nodesQueue.push_back(root); for (int r = 1; r < h; r++) { printBranches(branchLen, nodeSpaceLen, startLen, nodesInThisLevel, nodesQueue, out); branchLen = branchLen / 2 - 1; nodeSpaceLen = nodeSpaceLen / 2 + 1; startLen = branchLen + (3 - level) + indentSpace; printNodes(branchLen, nodeSpaceLen, startLen, nodesInThisLevel, nodesQueue, out); for (int i = 0; i < nodesInThisLevel; i++) { BinaryTree *currNode = nodesQueue.front(); nodesQueue.pop_front(); if (currNode) { nodesQueue.push_back(currNode->left); nodesQueue.push_back(currNode->right); } else { nodesQueue.push_back(NULL); nodesQueue.push_back(NULL); } } nodesInThisLevel *= 2; } printBranches(branchLen, nodeSpaceLen, startLen, nodesInThisLevel, nodesQueue, out); printLeaves(indentSpace, level, nodesInThisLevel, nodesQueue, out); }
std::string apply(NodePtrList &root) { m_so.str(""); m_d = 0; printNodes(root); return m_so.str(); }
void printNodes(IXML_Node *tmpRoot, int depth) { unsigned long i; IXML_NodeList *NodeList1; IXML_Node *ChildNode1; unsigned short NodeType; const DOMString NodeValue; const DOMString NodeName; NodeList1 = ixmlNode_getChildNodes(tmpRoot); for (i = 0; i < 100; ++i) { ChildNode1 = ixmlNodeList_item(NodeList1, i); if (ChildNode1 == NULL) { break; } printNodes(ChildNode1, depth+1); NodeType = ixmlNode_getNodeType(ChildNode1); NodeValue = ixmlNode_getNodeValue(ChildNode1); NodeName = ixmlNode_getNodeName(ChildNode1); IxmlPrintf(__FILE__, __LINE__, "printNodes", "DEPTH-%2d-IXML_Node Type %d, " "IXML_Node Name: %s, IXML_Node Value: %s\n", depth, NodeType, NodeName, NodeValue); } }
int main(){ struct Node node9 = {9, NULL}; struct Node node8 = {8, &node9}; struct Node node7 = {7, &node8}; struct Node node6 = {6, &node7}; struct Node node5 = {5, &node6}; struct Node node4 = {4, &node5}; struct Node node3 = {13, &node4}; struct Node node2 = {12, &node3}; struct Node node1 = {1, &node2}; printNodes(&node1); sortX(&node1, 7); printNodes(&node1); return 0; }
void KRadix2::printNodes(const std::vector<Node2>& nodes, int level) { for(const Node2& n : nodes) { qDebug() << QString("- ").repeated(level) << "Key:" << n.key.toString() << "Value:" << n.value << "Num of childnodes:" << n.childNodes.size(); if(!n.childNodes.empty()) { printNodes(n.childNodes, level + 1); } } }
void printNodes(struct Node* nd) { if (nd != NULL) { printf("key %d, address: %x, right: ",nd->key,*nd); if (nd->right !=NULL) { printf("%d, left: ", nd->right->key); } else { printf("NULL, left: "); } if (nd->left != NULL) { printf("%d\n",nd->left->key); } else { printf("NULL\n"); } printNodes(nd->left); printNodes(nd->right); } }
virtual void visit(Node_Element *v) { printKV("type", "element"); printKV("tag", v->tag); printAttris(v->attris); if (!v->children.empty()) { printTab(m_so, m_d); m_so << "children = "; printNodes(v->children); m_so << ",\n"; } }
int main(int argc, char** argv){ //build a BST that contains integers found on the command line //then print the integers in ascending order if(argc > 1){ NodePointer rp = createRoot( atoi (argv[1])); int i; for( i = 2; i < argc; i++){ rp = addNode( rp , atoi(argv[i])); }//for printNodes(rp); } //if exit(0); } //main(int, char**)
/* printNodes * little helping method to print tree with BAlerts */ void FileTree::printNodes(BList *nodes) { FileTree *tmpTree; BString strTMP = ""; if(!nodes->IsEmpty()) (new BAlert("", "Rekursion", "Exit"))->Go(); for(int i = 0; i < nodes->CountItems(); i++) { tmpTree = (FileTree*)nodes->ItemAt(i); (new BAlert("", "Schleife", "Exit"))->Go(); (new BAlert("", tmpTree->Path.String(), "Exit"))->Go(); printNodes(tmpTree->Nodes); } }
void printRootToLeafPaths(node* root, vector<node*> nodes) { if (!root) return; nodes.push_back(root); printRootToLeafPaths(root->left, nodes); // Leaf node if (!root->left && !root->right) { printNodes(nodes); } printRootToLeafPaths(root->right, nodes); nodes.pop_back(); }
int main(int argc, char *argv[]) { struct Node node[size]; int i = 0; // Init while (i < size) { node[i].x = i+1; i++; } // Find element 47. Find(47, node); Find(83, node); Insert(514, node); // print result printNodes(node); }
int main(void) { //linkedList pointer define start linkedList *L = (linkedList *)malloc(sizeof(linkedList)); L->cur = NULL; L->head = NULL; L->tail = NULL; //linkedList pointer define end createNode(L, 1); createNode(L, 2); createNode(L, 3); deleteLastNode(L); createNode(L, 4); createNode(L, 5); createNode(L, 6); deleteLastNode(L); deleteLastNode(L); createNode(L, 7); printNodes(L); return 0; }
/************************************************************************************* * Function: userInputMode() * Description: This is the function to handle User Input Mode * Return: 0-Success, 1-Unsucessful * Input: scheme - Fibonacci Heap or Leftist Tree, filePath - path of input file ************************************************************************************/ void userInputMode(char *scheme, char *filePath){ //struct f_node *f_root=NULL; //Root of Fibbonacci Heap pointer to Min tree //int operation, randomData; //To be used in Random Operation Generator FILE *inputFile; // User input File char operationUserInput[3] = {0}; //Operation in user input mode int userInputData, index, decreaseKeyBy; //Data in user input mode int fibonacciScheme, leftistScheme; inputFile = fopen(filePath, "r"); //Open input file in read mode if(strcmp(scheme, "-il") == 0){ //If scheme is Leftist Tree fibonacciScheme = 0; leftistScheme = 1; } else{ //If scheme is Fibonacci Heap fibonacciScheme = 1; leftistScheme = 0; } if(inputFile != NULL){ //If file is opened successfully if(log == DEBUG) printf("\nInitiating User mode Input...\n"); while(strcmp(operationUserInput, "*") != 0){ fscanf(inputFile, "%s", operationUserInput); //Scan first word //Delete Min Operation if(strcmp(operationUserInput, "D") == 0){ if(fibonacciScheme){ //If it is fibonacci Scheme if(log == DEBUG) printf("\nDeleting Min of Fibonacci Heap....\n"); MIN = deleteMin_MinFHeap(MIN); } else{ //If it is Leftist Tree if(log == DEBUG) printf("\nDeleting Min of Leftist Tree....\n"); ROOT = deleteMinLeftistTree(ROOT); } } //Insert Operation else if(strcmp(operationUserInput, "I") == 0){ fscanf(inputFile, "%d", &userInputData); //Read data if(fibonacciScheme){ //If it is fibonacci scheme if(log == DEBUG) printf("Inserting %d in Fibonacci Heap....\n", userInputData); MIN = insert_MinFHeap(MIN, userInputData); } else{ //If it is Leftist Tree if(log == DEBUG) printf("\nInserting %d in Leftist Tree....\n", userInputData); ROOT = insertMinLeftistTree(ROOT, userInputData); } } //Decrease Key else if(strcmp(operationUserInput, "DK") == 0){ fscanf(inputFile, "%d", &index); //Read index fscanf(inputFile, "%d", &decreaseKeyBy); //Read decreasekeyby if(fibonacciScheme){ if(log == DEBUG) printf("\nDecreasing Key of node at %d by %d....\n", index, decreaseKeyBy); MIN = decreaseKey(MIN, index, decreaseKeyBy); } } //Remove mode from Fibonacci Heap else if(strcmp(operationUserInput, "R") == 0){ fscanf(inputFile, "%d", &index); //Read index if(log == DEBUG ) printf("\nRemoving Key of node at %d....\n", index); MIN = removeMinFHeap(MIN, index); } } if(fibonacciScheme){ if(!print_MinFHeap(MIN)) printf("There was some problem in printing nodes!! Please try once again\n"); } else{ if(!printNodes(ROOT)) printf("There was some problem in printing nodes!! Please try once again\n"); } } else{ if(log == DEBUG || log == INFO) printf("Sorry, File is not accessible!\n"); } }
/* printNodes * little helping method to print tree to console */ void FileTree::printNodes() { printNodes(Nodes); }
void node::printNodes(node *subtree) { if(subtree == NULL) return; printNodes(subtree -> left); printf("%d\n", subtree -> value); printNodes(subtree -> right); }
int ModeGetNodes::execute() { const int mgmtTimeoutMS = 2500; int retVal = APPCODE_RUNTIME_ERROR; App* app = Program::getApp(); DatagramListener* dgramLis = app->getDatagramListener(); NodeStoreServers* mgmtNodes = app->getMgmtNodes(); std::string mgmtHost = app->getConfig()->getSysMgmtdHost(); unsigned short mgmtPortUDP = app->getConfig()->getConnMgmtdPortUDP(); StringMap* cfg = app->getConfig()->getUnknownConfigArgs(); NodeList nodes; StringSet unreachableNodes; // keys are nodeIDs, values unused uint16_t rootNodeID; // check arguments StringMapIter iter = cfg->find(MODEGETNODES_ARG_PRINTDETAILS); if(iter != cfg->end() ) { cfgPrintDetails = true; cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_PRINTNICDETAILS); if(iter != cfg->end() ) { cfgPrintNicDetails = true; cfgPrintDetails = true; // implied in this case cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_PRINTFHGFSVERSION); if(iter != cfg->end() ) { cfgPrintFhgfsVersion = true; cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_CHECKREACHABILITY); if(iter != cfg->end() ) { cfgCheckReachability = true; cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_REACHABILITYRETRIES); if(iter != cfg->end() ) { cfgReachabilityNumRetries = StringTk::strToUInt(iter->second); cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_REACHABILITYTIMEOUT_MS); if(iter != cfg->end() ) { cfgReachabilityRetryTimeoutMS = StringTk::strToUInt(iter->second); cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_PING); if(iter != cfg->end() ) { cfgPing = true; cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_PINGRETRIES); if(iter != cfg->end() ) { cfgPingRetries = StringTk::strToUInt(iter->second); cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_CONNTESTNUM); if(iter != cfg->end() ) { cfgConnTestNum = StringTk::strToUInt(iter->second); cfg->erase(iter); } iter = cfg->find(MODEGETNODES_ARG_CONNROUTE); if(iter != cfg->end() ) { cfgPrintConnRoute = true; cfg->erase(iter); } NodeType nodeType = ModeHelper::nodeTypeFromCfg(cfg); if(nodeType == NODETYPE_Invalid) { std::cerr << "Invalid or missing node type." << std::endl; return APPCODE_INVALID_CONFIG; } if(ModeHelper::checkInvalidArgs(cfg) ) return APPCODE_INVALID_CONFIG; // check mgmt node if(!NodesTk::waitForMgmtHeartbeat( NULL, dgramLis, mgmtNodes, mgmtHost, mgmtPortUDP, mgmtTimeoutMS) ) { std::cerr << "Management node communication failed: " << mgmtHost << std::endl; return APPCODE_RUNTIME_ERROR; } Node* mgmtNode = mgmtNodes->referenceFirstNode(); if(!NodesTk::downloadNodes(mgmtNode, nodeType, &nodes, false, &rootNodeID) ) { std::cerr << "Node download failed." << std::endl; retVal = APPCODE_RUNTIME_ERROR; goto cleanup_mgmt; } NodesTk::applyLocalNicCapsToList(app->getLocalNode(), &nodes); /* (downloaded node objects don't know the local nic caps initially) */ // check reachability if(cfgCheckReachability) ModeHelperGetNodes::checkReachability(nodeType, &nodes, &unreachableNodes, cfgReachabilityNumRetries, cfgReachabilityRetryTimeoutMS); // ping if(cfgPing) ModeHelperGetNodes::pingNodes(nodeType, &nodes, cfgPingRetries); // conn test if(cfgConnTestNum) ModeHelperGetNodes::connTest(nodeType, &nodes, cfgConnTestNum); // print nodes printNodes(nodeType, &nodes, &unreachableNodes, rootNodeID); retVal = APPCODE_NO_ERROR; // clean up NodesTk::deleteListNodes(&nodes); cleanup_mgmt: mgmtNodes->releaseNode(&mgmtNode); return retVal; }
void KRadix2::printNodes() { qDebug() << "--------------------------------------------------------"; printNodes(m_root.childNodes, 0); qDebug() << "--------------------------------------------------------"; }