singh.chakresh
BAN USER
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int A[] = {5, 4, 6, 10, 7, 8, 9, 11, 23, 40};
int size = sizeof(A) / sizeof(A[0]);
int B[100];
for (int i = 0; i < size; i++) {
B[i] = A[i];
}
sort(A, A + size);
for (int i = 0; i < size; i++) {
if (A[i] == B[i])
cout << i << " " << A[i] << endl;
}
return -1;
}
Are there negative numbers in the BST as well?
- singh.chakresh August 29, 2016//Left rotation of a string by N number of times;
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
int n;
char str [40];
cout<<"\n Enter the string: \n";
gets(str);
cout<<"\n How many times do yhou want to left rotate the string? \n";
cin>>n;
if(n%4 == 0)
puts(str);
if(n%4 == 1)
{
for(int i = 0; i< strlen(str); i++)
{
putchar(str[i]);
cout<<"\n";
}
}
if(n%4 == 2)
{
for(int i = strlen(str); i>=0; i--)
{
putchar(str[i]);
}
}
if(n%4 == 3)
{
for(int i = strlen(str); i>=0; i--)
{
putchar(str[i]);
cout<<"\n";
}
}
getch();
}
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char str[100], temp;
int i, j = 0;
printf("\n Enter the string: ");
gets(str);
i = 0;
j = strlen(str) - 1;
while(i<j){
temp = str[i];
str[i] = str[j];
str[j] = temp;
i++;
j--;
}
printf("\n The reversed string is: %s", str);
printf("\n \t The length of the string is: %d", strlen(str));
getch();
}
How about this:
1) Root node and leaf nodes will be there in the perimeter.
For all other nodes:
2) If the depth of the tree is n, then for first and last nodes of any level i will be in the perimeter.
3) the order in which the answer has to be printed can be determined by traversing the tree and checking for each node if it is filtered out by step 1 or 2.
start with:
- singh.chakresh March 08, 2017startIndex =0;
endIndex=0;