This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Node{ | |
struct Node *lchild; | |
int data; | |
int height; | |
struct Node *rchild; | |
}*root=NULL,*lleaf=NULL,*rleaf=NULL; // Pointing to Left and Right leaf nodes in BST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool hasCycle(ListNode *head) { | |
struct ListNode *p=head, *q=head; | |
if(!head || head->next==NULL){ | |
return false; | |
} | |
while(p!=NULL && p->next!=NULL){ | |
p=p->next->next; | |
q=q->next; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
void deleteNode(ListNode* node) { | |
struct ListNode *p=node; | |
if(p->next != NULL){ | |
p->val = p->next->val; | |
p->next = p->next->next; | |
}else{ | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Node{ | |
struct Node *lchild; | |
int data; | |
struct Node *rchild; | |
}*root=NULL; | |
void insert(int key){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int c = 0; | |
void postorder(struct Tree *p){ // Function to count number of nodes in the BT | |
if(p){ | |
postorder(p->lchild); | |
postorder(p->rchild); | |
cout << p->data << " "; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Tree{ | |
struct Tree *lchild; | |
int data; | |
struct Tree *rchild; | |
}*root=NULL; | |
struct Node{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Node{ | |
struct Node *lchild; | |
int data; | |
struct Node *rchild; | |
}*root=NULL; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct queue{ | |
int size; | |
int front; | |
int rear; | |
int *Q; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct Queue{ | |
int size; | |
int front; | |
int rear; | |
int *Q; | |
}; |