在本教程中,我们将讨论一个程序,该程序使用队列数据结构将二叉树转换为线程二叉树。为此,我们将提供一个二叉树。我们的任务是通过添加额外的路由来更快地进行中序遍历,借助队列数据结构将特定的二叉树转换为线程二叉树。示例 在线演示#include #include using namespace std; //node structure for threaded tree struct Node { int key; Node *left, *right; bool isThreaded; }; //putting the inorder pattern into a queue void convert_queue(Node* root, std::queue* ... 阅读更多
在本教程中,我们将讨论一个程序,该程序将二叉树转换为循环双向链表。为此,我们将提供一个二叉树。我们的任务将是分别将左节点和右节点转换为左元素和右元素。并取二叉树的中序作为循环链表的顺序示例 在线演示#include using namespace std; //node structure of the binary tree struct Node{ struct Node *left, *right; int data; }; //appending rightlist to the end of leftlist Node *concatenate(Node *leftList, Node *rightList){ //if ... 阅读更多
在本教程中,我们将讨论一个程序,该程序将转换二叉树,以便每个节点存储其右子树中所有节点的和。为此,我们将提供一个二叉树。我们的任务是返回另一棵树,其中每个节点必须等于节点及其右子树的和。示例 在线演示#include using namespace std; //node structure of tree struct Node { int data; Node *left, *right; }; //creation of a new node struct Node* createNode(int item){ Node* temp = new Node; temp->data = item; ... 阅读更多
在本教程中,我们将讨论一个打印最后 N 行的程序。为此,我们将提供一个包含换行符的字符串,以表示下一行的开始以及要从最后打印的行数。我们的任务是从最后开始,打印从最后开始计算的所有 N 行。示例#include using namespace std; #define DELIM '' //printing the last N lines void print_last_lines(char *str, int n){ if (n
在本教程中,我们将讨论一个打印最后 10 行的程序。为此,我们将提供一个包含换行符的字符串,以表示下一行的开始。我们的任务是从最后开始,打印从最后开始计算的所有 10 行。示例#include using namespace std; #define DELIM '' //printing the last 10 lines void print_last_lines(char *str, int n){ if (n
在本教程中,我们将讨论一个打印给定风筝图案的程序。为此,我们将输入为 N=5。我们的任务是打印给定的风筝结构,其总高度为 2N+1 = 5。这包括上部菱形结构的 9 行和下部不完整菱形结构的 2 行。示例 在线演示#include #include using namespace std; int main(){ int i, j, k, sp, space = 4; char prt = '$'; //printing the upper half of the first diamond for (i = 1; i = 1; sp--){ cout