#include<iostream>#include<queue>
using namespace std;structNode{int data;structNode* left,*right;};// Function to count the full Nodes in a binary treeintfullcount(structNode* node){// Check if tree is emptyif(!node){return0;}
queue<Node *> myqueue;// traverse using level order traversingint result =0;
myqueue.push(node);while(!myqueue.empty()){structNode*temp = myqueue.front();
myqueue.pop();if(temp->left && temp->right){
result++;}if(temp->left !=NULL){
myqueue.push(temp->left);}if(temp->right !=NULL){
myqueue.push(temp->right);}}return result;}structNode*newNode(int data){structNode* node = new Node;
node->data = data;
node->left = node->right =NULL;return(node);}intmain(void){structNode*root =newNode(10);
root->left =newNode(20);
root->right =newNode(30);
root->left->left =newNode(40);
root->left->right =newNode(50);
root->left->left->right =newNode(60);
root->left->right->right =newNode(70);
cout <<"count is: "<<fullcount(root);return0;}
#include<iostream>#include<queue>
using namespace std;structNode{int data;structNode* left,*right;};// Function to count the full Nodes in a binary treeintfullcount(structNode* node){// Check if tree is emptyif(!node){return0;}
queue<Node *> myqueue;// traverse using level order traversingint result =0;
myqueue.push(node);while(!myqueue.empty()){structNode*temp = myqueue.front();
myqueue.pop();if(temp->left && temp->right){
result++;}if(temp->left !=NULL){
myqueue.push(temp->left);}if(temp->right !=NULL){
myqueue.push(temp->right);}}return result;}structNode*newNode(int data){structNode* node = new Node;
node->data = data;
node->left = node->right =NULL;return(node);}intmain(void){structNode*root =newNode(10);
root->left =newNode(20);
root->right =newNode(30);
root->left->left =newNode(40);
root->left->right =newNode(50);
root->left->left->right =newNode(60);
root->left->right->right =newNode(70);
cout <<"count is: "<<fullcount(root);return0;}
#include<iostream>#include<queue>
using namespace std;structNode{int data;structNode* left,*right;};// Function to count the full Nodes in a binary treeintfullcount(structNode* node){// Check if tree is emptyif(!node){return0;}
queue<Node *> myqueue;// traverse using level order traversingint result =0;
myqueue.push(node);while(!myqueue.empty()){structNode*temp = myqueue.front();
myqueue.pop();if(temp->left && temp->right){
result++;}if(temp->left !=NULL){
myqueue.push(temp->left);}if(temp->right !=NULL){
myqueue.push(temp->right);}}return result;}structNode*newNode(int data){structNode* node = new Node;
node->data = data;
node->left = node->right =NULL;return(node);}intmain(void){structNode*root =newNode(10);
root->left =newNode(20);
root->right =newNode(30);
root->left->left =newNode(40);
root->left->right =newNode(50);
root->left->left->right =newNode(60);
root->left->right->right =newNode(70);
cout <<"count is: "<<fullcount(root);return0;}
#include<iostream>#include<queue>
using namespace std;structNode{int data;structNode* left,*right;};// Function to count the full Nodes in a binary treeintfullcount(structNode* node){// Check if tree is emptyif(!node){return0;}
queue<Node *> myqueue;// traverse using level order traversingint result =0;
myqueue.push(node);while(!myqueue.empty()){structNode*temp = myqueue.front();
myqueue.pop();if(temp->left && temp->right){
result++;}if(temp->left !=NULL){
myqueue.push(temp->left);}if(temp->right !=NULL){
myqueue.push(temp->right);}}return result;}structNode*newNode(int data){structNode* node = new Node;
node->data = data;
node->left = node->right =NULL;return(node);}intmain(void){structNode*root =newNode(10);
root->left =newNode(20);
root->right =newNode(30);
root->left->left =newNode(40);
root->left->right =newNode(50);
root->left->left->right =newNode(60);
root->left->right->right =newNode(70);
cout <<"count is: "<<fullcount(root);return0;}
// C++ program to generate n-bit Gray codes#include<iostream>#include<string>#include<vector>
using namespace std;// This function generates all n bit Gray codes and prints the// generated codesvoidgenerateGrayarr(int n){// base caseif(n <=0)return;// 'arr' will store all generated codes
vector<string> arr;// start with one-bit pattern
arr.push_back("0");
arr.push_back("1");// Every iteration of this loop generates 2*i codes from previously// generated i codes.int i, j;for(i =2; i <(1<<n); i = i<<1){// Enter the previously generated codes again in arr[] in reverse// order. Nor arr[] has double number of codes.for(j = i-1; j >=0; j--)
arr.push_back(arr[j]);// append 0 to the first halffor(j =0; j < i ; j++)
arr[j]="0"+ arr[j];// append 1 to the second halffor(j = i ; j <2*i ; j++)
arr[j]="1"+ arr[j];}// print contents of arr[]for(i =0; i < arr.size(); i++)
cout << arr[i]<< endl;}// Driver program to test above functionintmain(){generateGrayarr(3);return0;}
#include<stdio.h>#include<stdlib.h>//Represent a node of singly linked list structnode{int data;structnode*next;};//Represent the head and tail of the singly linked list structnode*head,*tail =NULL;//addNode() will add a new node to the list voidaddNode(int data){//Create a new node structnode*newNode =(structnode*)malloc(sizeof(structnode));
newNode->data = data;
newNode->next =NULL;//Checks if the list is empty if(head ==NULL){//If list is empty, both head and tail will point to new node
head = newNode;
tail = newNode;}else{//newNode will be added after tail such that tail's next will point to newNode
tail->next = newNode;//newNode will become new tail of the list
tail = newNode;}}//display() will display all the nodes present in the list voiddisplay(){//Node current will point to head structnode*current = head;if(head ==NULL){printf("List is empty
");return;}printf("Nodes of singly linked list:
");while(current !=NULL){//Prints each node by incrementing pointer printf("%d ", current->data);
current = current->next;}printf("
");}intmain(){//Add nodes to the list addNode(1);addNode(2);addNode(3);addNode(4);//Displays the nodes present in the list display();return0;}
#include<stdio.h>intmain(){int num, max, min;printf("Enter four numbers: ");scanf("%d",&num);
max = min = num;for(int i =0; i <3; i++){scanf("%d",&num);if(max < num)
max = num;elseif(min > num)
min = num;}printf("The smallest and largest of given four numbers are %d and %d respectively.
", min, max);return0;}