Monday, September 16, 2019

Write a java program to compare two strings lexicographicall

Write a java program to compare two strings lexicographically.
Using the compareTo method for comparing the String .
compareTo method is compare the string is based on the unicode value of character .
It return the positive negative and zero value.
if the string are same it return the zero value otherwise it positive or negative value depend on ASCII value of the character .
for example
1st string is s1 = middle
2nd string is s2 = niddle
so it return the value is -1.
bcoz the value of m is 77 and value of n is 78 (ASCII)
so 77 -78 = -1
so the return value is -1 .
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
String s1;
String s2;
s1 = obj.nextLine();
s2 =obj.nextLine();
if(s1.compareTo(s2)==0){
System.out.println("string are equal"); }
else{
System.out.println("not "+s1.compareTo(s2)+" is difference ");
} } }

Output:  
  oneo
  oneof
  not -1 is difference.
                

Saturday, September 14, 2019

Amazing and gorgeous calculator theme.

Calculator Vikas Tomar's DEV Profile

Amazing and gorgeous calculator theme.

% UR x2 1/x
CE C BK /
7 8 9 *
4 5 6 -
1 2 3 +
% 0 . =
Calculator

If You wanna to show the coding of this theme click on this

Monday, September 9, 2019

Turtle (python)

clever Vikas Tomar's DEV Profile
                    import turtle 
                    # give the turtle name;
                    clever = turtle.Turtle()
                    clever.color('green')
                    clever.speed(0)
  
                   def draw_square():
                   for side in range(4):
                   clever.forward(100)
                   clever.right(90)
                   for anothersquare in range(4):
                   clever.forward(50)
                   clever.right(90)
                   
                   draw_square()
                   def lotofsquare():
                   for square in range(30):
    
                   clever.color('green')
                   draw_square()
                   clever.penup()
                   clever.forward(20)
                   clever.left(50)
                   clever.pendown()
                   lotofsquare()

IF WE WANT TO SEE OUTPUT CLICK THE BELOW LINK

Sunday, March 3, 2019

Introduction of Unicode (python)

Introduction of Unicode

Vikas Tomar's DEV Profile
The American Standard Code for Information Interchange, better known by its acronym ASCII, was standardized. ASCII defined numeric codes for various characters, with the numeric values running from 0 to 127

  • Unicode Provide the Unique number for every Character, like as the Uppercase letter 'A' is assigned the '65' Code Value. 
  • Unicode consist of Uppercase ,lowercase letter, emoji , each each every character as code value.
  • Unicode may be 8 bit ,16 bit Or 32 bit..




Unicode has lot of benefit in programming and Unicode doesn't matter what the Platform, what Language , what  Program.

  • Let See Example Of Using ASCII Value:
  •  ASCII Code(65  to 90)

for i in range(65,91):
    print(chr(i),end=" ")
#OUTPUT A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 

  • Similar we can use the lowercase alphabets by using (97 to 121) ASCII code value.


UNICODE TABLE :            
                                           

Properties :

UTF-8 is one of the most commonly used encodings. UTF stands for “Unicode Transformation Format”, and the ‘8’ means that 8-bit numbers are used in the encoding. (There’s also a UTF-16 encoding, but it’s less frequently used than UTF-8.) UTF-8 uses the following rules:

If the code point is <128, it’s represented by the corresponding byte value.
If the code point is between 128 and 0x7ff, it’s turned into two byte values between 128 and 255.
Code points >0x7ff are turned into three- or four-byte sequences, where each byte of the sequence is between 128 and 255.

UTF-8 has several convenient properties:

It can handle any Unicode code point.
A Unicode string is turned into a string of bytes containing no embedded zero bytes. This avoids byte-ordering issues, and means UTF-8 strings can be processed by C functions such as strcpy() and sent through protocols that can’t handle zero bytes.

A string of ASCII text is also valid UTF-8 text.
UTF-8 is fairly compact; the majority of code points are turned into two bytes, and values less than 128 occupy only a single byte.

If bytes are corrupted or lost, it’s possible to determine the start of the next UTF-8-encoded code point and resynchronize. It’s also unlikely that random 8-bit data will look like valid UTF-8.

Unicode Properties

The Unicode specification includes a database of information about code points.
import unicodedata
u = chr(233) + chr(0x0bf2) + chr(3972) + chr(6000) + chr(13231)
for i, c in enumerate(u):
    print(i, '%04x' % ord(c), unicodedata.category(c), end=" ")
    print(unicodedata.name(c))


  • Explanation : 


%04x is a format specifier, which only makes sense with the % operator. It specifies that the number to be formatted (in this case, ord(c)  should be formatted as a hexadecimal with four digits and zero-padding on the left. So if c is "A" , whose Unicode code point is 65, it will be printed as 0041 .


  • Unicodedata.category(chr)


This function returns the general category assigned to the given character as string. For example, it returns ‘L’ for letter and ‘u’ for uppercase.

  • Example :

import unicodedata 
print unicodedata.category(u'A') 
print unicodedata.category(u'b') 

  • Output : Lu                                            # Letter Lowercase .


                       Ll                                             # Letter Uppercase .







Monday, February 25, 2019

Insert node in red black tree

Insert The Node In Red Black Tree

properties:

~Insert

 Node must be red.

~Arranged the color according to the Red Black Tree.

Root is always black

Every leaf  which nil (null) is black.

If node is red then both children must be black or if node is red, then its parent must be black.

~Rotation 

  According to the cases.

  There are case in given below.

~ Violation of properties of red black tree.

Case :

case 1. After insert.(New Node uncle is red).

1.Change the color of grandparent of new node. 
   2.Change the color of parent and uncle of new node.  

~ New node unle is black and New node is right child of the parent.
  

Follow this :
1. Anti-clock wise Rotation of the grandparent of the new node.
~ New Node uncle is black and new node is left child of it's parent .



 Follow this : 
1.Clockwise rotation of the grandparent of new node.
2. Exchange color of the grandparent and parent of new node.

Saturday, February 23, 2019

Bubble Sort(python)

SORTING

Sorting is a process to arranged the data in some type of order.
This is order may increasing, decreasing and numerical value or dictionary
in case of alphanumerical values.
Bubble Sort.
Bubble sort is very simple and easy to implement the sorting technique
Algorithm 
Bubblesort(a,n)

Here a is a linear array of n element
Step
1. Repeat step 2 and 3 for i= 1 to n-1.
2. Set j=1 [ Intilize counter ].
3. Repeat Step While(j>n-1)

     $). if a[i] > a[i+1] then 
         interchange  a[i] and  a[i+1]
         End if structure. 
     $). j= j+1.
    End of inner loop.
 End of step 1 outer loop.
 4.Exit

Program to write the Bubble sort..

def bubbleSort(a):

n = len(a) for i in range(n): for j in range(0, n - i - 1): if a[j] > a[j + 1]: temp=a[j] a[j] = a[j+1] a[j+1]=temp # Or we can a[j], a[j + 1] = a[j + 1], a[j] # before sorted array. a = [4, 3, 5, 1, 2, 11, 20,45,22,63] # function for bubble sort. bubbleSort(a) print("After Sorted array is:") # b indicate the size of the array. b = len(a) for i in range(b): print(a[i],end=" ")

Red black tree(Introduction)

Vikas Tomar's DEV Profile

Red black tree (Introduction)

Red black tree is special type of binary search tree. It is self balancing binary search tree like as (AVL tree).
Some properties must be follow for red black tree.
Properties:
  • Every node has a color either Black and red.
  • Root node always a black.
  • Every leaf  which nil (null) is black.
  • If node is red then both children must be black or if node is red, then its parent must be black.
  • for n node, all path form the to descendant leaves contain the same number of black node




              




NOTE ⇉  Whenever root is red node then we remove node by black node.

 



Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...