Convert binary tree to a doubly linked list
C++
#include <iostream>
using namespace std;
void BinaryTree2DoubleLinkedList(node *root, node **head)
{
if (root == NULL) return;
static node* prev = NULL;
BinaryTree2DoubleLinkedList(root->left, head);
if (prev == NULL)
*head = root;
else
{
root->left = prev;
prev->right = root;
}
prev = root;
BinaryTree2DoubleLinkedList(root->right, head);
}
node* newNode(int data)
{
node* new_node = new node;
new_node->data = data;
new_node->left = new_node->right = NULL;
return (new_node);
}
void printList(node *node)
{
while (node!=NULL)
{
cout << node->data << " ";
node = node->right;
}
}
Also in C++:
- Title
- c++ yes no question
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- how to turn int into string c++
- Category
- C++
- Title
- binary search in set c++
- Category
- C++
- Title
- program to know if a number is prime
- Category
- C++
- Title
- convert char to string - c++
- Category
- C++
- Title
- ios_base::sync_with_stdio(false);cin.tie(NULL);
- Category
- C++
- Title
- pass vector by reference c++
- Category
- C++
- Title
- bool function in c++
- Category
- C++
- Title
- google pdf iframe viwer
- Category
- C++
- Title
- c++ crash windows
- Category
- C++
- Title
- getline in c++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- c++ write string
- Category
- C++
- Title
- get data from terminal c++
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- mingw32/bin/ld.exe: C:\Users\mfrom\AppData\Local\Temp\ccSKcRks.o:PizzaPi.cpp:(.text$_ZN5PizzaC2Ev[__ZN5PizzaC2Ev]+0xa): undefined reference to `vtable for Pizza' collect2.exe: error: ld returned 1 exit status
- Category
- C++
- Title
- dijkstra in c++
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- cout value c++
- Category
- C++
- Title
- create copy of range of string c++
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- swapo algorit
- Category
- C++
- Title
- print type cpp
- Category
- C++
- Title
- insert function in c++ vector
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- modular exponentiation c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- c++ while true
- Category
- C++
- Title
- how to delete a node c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- count function c++
- Category
- C++
- Title
- binary search stl in c++
- Category
- C++
- Title
- c++ while true loop
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- struct c++
- Category
- C++
- Title
- range of long long in c++
- Category
- C++
- Title
- initialise 2d vector in c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- for loop
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- Runtime Error: Runtime ErrorBad memory access (SIGBUS)
- Category
- C++
- Title
- case label in c++
- Category
- C++
- Title
- how to get os name in c++
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++
- Title
- stl sort in c++
- Category
- C++
- Title
- conditional operator in cpp
- Category
- C++
- Title
- command line options in c++
- Category
- C++
- Title
- generate random double c++
- Category
- C++
- Title
- check for bst
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- char vector to string c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- qt make widget ignore mouse events
- Category
- C++
- Title
- c++ vector iterator
- Category
- C++
- Title
- c++ print one line to console instead of multiple
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- registering a new QML type
- Category
- C++
- Title
- dynamic 2d array c++
- Category
- C++
- Title
- memcmp in cpp
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- arduino falling edge
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- string substr c++
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- find in vector in c++
- Category
- C++
- Title
- restting a queue stl
- Category
- C++
- Title
- delete files c++
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- double max value c++
- Category
- C++
- Title
- rosrun actionlib_msgs genaction.py
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- bfs in C++
- Category
- C++
- Title
- pairs in c++
- Category
- C++
- Title
- c++ vector add element
- Category
- C++
- Title
- translate
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- cin.ignore
- Category
- C++
- Title
- compile c++ program
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- c++ typedef
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- c++ allocate dynamic with initial values
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- error: invalid use of template-name without an argument list
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- random number generator c++
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- how read a shader from another file c++
- Category
- C++
- Title
- create a 2d array c++
- Category
- C++