To debug a C-program in gdb, compile the program and use the following command to enter into gdb mode in linux terminal – gdb ./your_program…
[wpdm_package id=’1161′] We have seen sorting on numbers in arrays. Now what about sorting a linked list using bubble sort? Before we continue, we must…
[wpdm_package id=’1177′] Appending a linked list onto another is pretty easy. All you have to do is, make the last node’s next pointer of the…
[wpdm_package id=’1405′] Algorithm: [sourcecode lang=”cpp”] void RemoveDuplicates(intnode* head) { intnode* current = head; if (current == NULL) return; // do nothing if the list is…
[wpdm_package id=’1413′] We had discussed here a few applications of stack. And here is another one. Converting positive decimals to binary using a stack. You…
[wpdm_package id=’1352′] Algorithm: Use Recursion. If both the trees are NULL, return true. If only one of the trees is NULL return false. Recursively find…
[wpdm_package id=’1354′] Algorithm: [sourcecode lang=”cpp”] void DeleteBinaryTree(tree_node *root) { if(!root) return; DeleteBinaryTree(root->left); DeleteBinaryTree(root->right); free(root); } [/sourcecode]
[wpdm_package id=’1359′] Algorithm: Return true if both the trees are empty. Return false if only one of the tree is empty. Return false if root…
[wpdm_package id=’1361′] Algorithm: [sourcecode lang=”cpp”] int FindLevelWithMaxSum() { tree_node *temp; int level=0, maxLevel=0; std::queue<tree_node *> Q; int currentSum=0, maxSum=0; if(!root) return 0; Q.push(root); Q.push(NULL); while(!Q.empty())…