How recursive bubble sort work

                                              Recursive Bubble Sort Base Case: If array size is 1, return. Do One Pass of normal Bubble Sort. This pass fixes last element of current subarray. Recur for all elements except last of current subarray. Example: Index=     0 1  2 3 4 5 6 7   100                          90 80 70 60 50 40 30  Array []= Suppose we want to sort the above in the increasing order by the recursive bubble sort. Make a get grater which will return the grater of the array. Compare the first and last element of the array if the first is greater than last the swap with each other. And again call the sort function and decrement the array size by 1; 1) 30                     90 80 70 60 50 40 100    ...

simple calculator apps project in android studio

                                        calculator apps 







 

 

                                                          XML CODE

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:orientation="vertical"
   
android:padding="16dp"
   
tools:context=".MainActivity">

    <TextView
       
android:id="@+id/tvResult"
       
android:layout_width="375dp"
       
android:layout_height="137dp"
       
android:background="#C8C8D6"
       
android:hint="result"
       
android:textSize="20dp" />

    <LinearLayout
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:orientation="horizontal"
       
android:padding="10dp">

        <Button
           
android:id="@+id/btnOne"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:background="#93939E"
           
android:text="1"
           
android:textSize="20dp" />

        <Button
           
android:id="@+id/btnTwo"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:background="#93939E"
           
android:text="2"
           
android:textSize="20dp" />

        <Button
           
android:id="@+id/btnThree"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:background="#93939E"
            
android:text="3"
           
android:textSize="20dp" />

        <Button
           
android:id="@+id/btnPlus"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:background="#FD3636"
            
android:text="+"
           
android:textSize="20dp" />
    </LinearLayout>

    <LinearLayout
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:orientation="horizontal"
       
android:padding="10dp"
       
>

        <Button
           
android:id="@+id/btnFour"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="4"
           
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnFive"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"

           
android:text="5"
            
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnSix"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="6"
            
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnMinus"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="-"
           
android:background="#FD3636"
            
android:textSize="20dp"/>
    </LinearLayout>
    <LinearLayout

       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:padding="10dp"
       
android:orientation="horizontal">

        <Button
            
android:id="@+id/btnSeven"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="7"
           
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnEight"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="8"
           
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnNine"
           
android:background="#93939E"
           
android:textSize="20dp"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="9" />

        <Button
           
android:id="@+id/btnMultiply"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="x"
           
android:background="#FD3636"
           
android:textSize="20dp"/>
    </LinearLayout>
    <LinearLayout
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:orientation="horizontal"
       
android:padding="10dp"
       
android:textSize="20dp">

        <Button
            
android:id="@+id/btnZero"
           
android:background="#93939E"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="0"
           
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnEqual"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="="
           
android:background="#C1FA1D"
           
android:textSize="20dp"/>

        <Button
           
android:id="@+id/btnDivider"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:textSize="20dp"
           
android:background="#C1FA1D"
           
android:text="/" />

        <Button
           
android:textSize="20dp"
           
android:id="@+id/btnMode"
           
android:layout_width="wrap_content"
           
android:layout_height="wrap_content"
           
android:text="%"
           
android:background="#C1FA1D"/>
    </LinearLayout>

    <Button
       
android:id="@+id/btnClear"
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:text="Clear"

       
android:background="#F30B0B"/>


</LinearLayout>

 

 

 

 

 

                                                                 

 

 

 

 

                                                          JAVA CODE

package com.example.calculateractivity;

import
androidx.appcompat.app.AppCompatActivity;

import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.TextView;

public class
MainActivity extends AppCompatActivity {
    Button
btnOne,btnTwo,btnThree,btnFour,btnFive,btnSix,btnSeven,btnEight,btnNine,btnZero;
   
Button btnMode,btnPlus,btnMinus,btnMultiply,btnEqual,btnDivider;
   
Button bntClear;
   
TextView tvResult;
    boolean
add,sub,div,mul,mod;
    double
var1,var2;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
       
setContentView(R.layout.activity_main);
       
btnOne=findViewById(R.id.btnOne);
       
btnDivider=findViewById(R.id.btnDivider);
       
btnTwo=findViewById(R.id.btnTwo);
       
btnThree=findViewById(R.id.btnThree);
       
btnFour=findViewById(R.id.btnFour);
       
btnFive=findViewById(R.id.btnFive);
       
btnSix=findViewById(R.id.btnSix);
        
btnSeven=findViewById(R.id.btnSeven);
       
btnEight=findViewById(R.id.btnEight);
       
btnEqual=findViewById(R.id.btnEqual);
       
btnNine=findViewById(R.id.btnNine);
       
btnZero=findViewById(R.id.btnZero);
       
btnMinus=findViewById(R.id.btnMinus);
       
btnMode=findViewById(R.id.btnMode);
       
btnMultiply=findViewById(R.id.btnMultiply);
       
btnPlus=findViewById(R.id.btnPlus);
       
tvResult=findViewById(R.id.tvResult);
       
bntClear=findViewById(R.id.btnClear);

       
btnDivider.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
                 
var1=Double.parseDouble(tvResult.getText()+"");
                 
div=true;
                 
tvResult.setText("");
           
}
        })
;

       
btnPlus.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
var1=Double.parseDouble(tvResult.getText()+" ");
               
add=true;
            
tvResult.setText("");
           
}
        })
;
       
btnMinus.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
var1=Double.parseDouble(tvResult.getText()+" ");
                
sub=true;
               
tvResult.setText("");
           
}
        })
;
       
btnMultiply.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
var1=Double.parseDouble(tvResult.getText()+" ");
               
mul=true;
               
tvResult.setText("");
           
}
        })
;

       
btnMode.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
var1=Double.parseDouble(tvResult.getText()+" ");
               
mod=true;
               
tvResult.setText("");
           
}
        })
;
       
btnEqual.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
var2=Double.parseDouble(tvResult.getText()+"");
                if
(add == true)
                {
                   
tvResult.setText(var1+var2 + " ");
                   
add=false;
               
}
               
if (add == true)
                {
                   
tvResult.setText(var1+var2 + "");
                   
add=false;
               
}
               
if (sub == true)
                {
                   
tvResult.setText(var1-var2 + " ");
                   
sub=false;
               
}
               
if (mul == true)
                {
                   
tvResult.setText(var1*var2 + " ");
                   
mul=false;
               
}

               
if (mod == true)
                {
                   
tvResult.setText(var1%var2 + " ");
                   
mod=false;
               
}
            }
        })
;
       
btnOne.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"1");
           
}
        })
;
       
btnTwo.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"1");
           
}
        })
;
       
btnTwo.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"1");
           
}
        })
;
       
btnTwo.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"2");
           
}
        })
;
       
btnThree.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"3");
           
}
        })
;
       
btnFour.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"4");
           
}
        })
;
       
btnFive.setOnClickListener(new View.OnClickListener() {
            
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"5");
           
}
        })
;
       
btnSix.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"6");
           
}
        })
;
       
btnSeven.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
                
tvResult.setText(tvResult.getText().toString() +"7");
           
}
        })
;
       
btnEight.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"8");
           
}
        })
;
       
btnNine.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"9");
           
}
        })
;
       
btnZero.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText(tvResult.getText().toString() +"0");
           
}
        })
;
        
bntClear.setOnClickListener(new View.OnClickListener() {
           
@Override
           
public void onClick(View v) {
               
tvResult.setText("");
           
}
        })
;

   
}
}

 

 

Comments

Popular posts from this blog

Arrays in C Programming Language

Pointers in C