Maniruzzaman Akash's Blog

Maniruzzaman Akash, A programmer, A web programmer, a helpful person to share knowledge and everything..

  • Home
  • Programming
    • C Programming
    • Java Programming
    • C++ Programming
    • C# Programming
    • Python Programming
    • Data Structure
  • Web
    • HTML
    • CSS
    • Javascript
    • PHP
    • AJAX
    • XML
  • FrameWork
    • Bootstrap(CSS)
    • Laravel 5(PHP)
  • Database
    • MySQL
    • Oracle
    • SQL Server
  • Android
    • Android Development
  • Mathematics
    • Numerical Methods
  • Others
    • My Articles
    • Download Ebooks
    • Mathematics
    • Difference Between
  • Contact
Showing posts with label Java Programming. Show all posts
Data Structure Java Programming

Infix to postfix code in java language : Data structures

Friday, February 3, 2017 By Maniruzzaman Akash 0 Comments
Infix to postfix code in java language : Data structures:

Description:
When we give any calculating instruction to our computer or mobile phones then, it calculate that by method or a converting method. When we give some input in computer it is in the infix expression. Look in the table.And finally we get the result.

Like, if we calculate 4 * 5 + 3 then, result is 23. And in this case this 4 * 5 + 3  is the infix notation, and finally we get the result by converting this expression to postfix and after evaluating that we can get the result of 23. So, let's look at the following table of infix to postfix expression.

Infix ExpressionPrefix ExpressionPostfix Expression
A + B+ A BA B +
A + B * C+ A * B CA B C * +

Code Demonstration of infix to postfix convert java code:



package infixtopostfix;



import java.util.Stack;

import java.util.Scanner;



public class InfixToPostfix {

    static int getPrecedence(char checkChar)

    {

        if(checkChar=='+'||checkChar=='-')

            return 1;

         if(checkChar=='*'||checkChar=='/')

            return 2;

         if(checkChar=='('||checkChar==')')

            return 0;

         return -1;   

    }



    public static void main(String[] args) {

       Stack<Character> stack=new Stack();

       Scanner scanner =new Scanner(System.in);

       String result="";

       String inputStr=scanner.nextLine();

       char[] inputCharArray=inputStr.toCharArray();

       for(char chrac:inputCharArray)

           System.out.println(chrac);

       for(int i=0;i<inputCharArray.length;i++)

       {

           char checkChar=inputCharArray[i];

           if(checkChar!='+'&&checkChar!='-'&&checkChar!='/'&&checkChar!='*'&&checkChar!='('&&checkChar!=')')

           {

               result=result+checkChar;

           }

          

          

           else 

           {    

               if(checkChar!='('&&checkChar!=')')

               {

                   if(stack.isEmpty())

               {

                   stack.push(checkChar);

               }

               else

               {

                

                while(getPrecedence(stack.peek())>=getPrecedence(checkChar))

              {  

                  result=result+stack.pop();

                if(stack.isEmpty())

                    break;

              }

             stack.push(checkChar);

               }

              

               }

               else

               {

                   if(checkChar=='(')

                       stack.push(checkChar);

                   else

                   {

                       while(stack.peek()!='(')

                       {

                           result=result+stack.pop();

                       }

                       stack.pop();

                   }

               }

       }

          

          

    }

       while(!stack.isEmpty())

           result=result+stack.pop();

      

       System.out.println(result);

}

}



This is a simple code if mine of infix to postfix notation in java language.

Demonstrate the code of infix to postfix:

I've written a very simple code not so hard. We can understand it quickly hopefully.
First look at the infix to postfix algorithm.

In this Algorithm we are reading token from Left to Right and Postfix expression is generated.

(1) So Entered Token may be –

  1. Alphabet from A-Z or a-Z
  2. Numerical Digit from 0-9
  3. Operator
  4. Opening And Closing Braces ( , )

(2) If Entered Character is Alphabet then Following Action Should be taken-

  1. Print Alphabet as Output

(3) If Entered Character is Digit then Following Action Should be taken-

  1. Print Digit as Output

(4) If Entered Character is Opening Bracket then Following Action Should be taken-

  1. Push ‘(‘ Onto Stack

(5) If any Operator Appears before ‘)’ then

  1.  Push it onto Stack.
  2. If Corresponding ‘)’ bracket appears then Start Removing Elements [Pop] from Stack till ‘(‘ is removed.

(6) If Entered Character is Operator then Following Action Should be taken-

  1. Check Whether There is any Operator Already present in Stack or not.
  2. If Stack is Empty then Push Operator Onto Stack.
  3. If Present then Check Whether Priority of Incoming Operator is greater than Priority of Topmost Stack Operator.
  4. If Priority of Incoming Operator is Greater then Push Incoming Operator Onto Stack.
  5. Else Pop Operator From Stack again goto Step 6.

Domonstrate:
We may get a number or operator and we take our operation character by character.

  1. If character is alphabet or digit then print that as output.
  2. If get "(" then push in into stack and when get any ")" then search upto ")" and removing value from this to stack and remove the "("
  3. If any character entered then check the operator precedence of that character and do like as algorithm rule 6.


By this method,
    static int getPrecedence(char checkChar)

    {

        if(checkChar=='+'||checkChar=='-')

            return 1;

         if(checkChar=='*'||checkChar=='/')

            return 2;

         if(checkChar=='('||checkChar==')')

            return 0;

         return -1;   

    }
We've check the operator precedence of the character given.

And in this line,
       String inputStr=scanner.nextLine();

       char[] inputCharArray=inputStr.toCharArray();

       for(char chrac:inputCharArray)

           System.out.println(chrac);

Make an inputCharArray of character and by using foreach loop print all of them.

By this line:
for(int i=0;i<inputCharArray.length;i++)
Run the loop upto input character length.

By this line:
if(checkChar!='+'&&checkChar!='-'&&checkChar!='/'&&checkChar!='*'&&checkChar!='('&&checkChar!=')')

           {

               result=result+checkChar;

           }
If check character is Alphabet or digit then add this to result.

And by this line:
if(checkChar!='('&&checkChar!=')')

               {

                   if(stack.isEmpty())

               {

                   stack.push(checkChar);

               }

               else

               {

                

                while(getPrecedence(stack.peek())>=getPrecedence(checkChar))

              {  

                  result=result+stack.pop();

                if(stack.isEmpty())

                    break;

              }

             stack.push(checkChar);

               }

If check character is +, -, * or / then check the precedence. Pop the higher precedence from the output and add it to result and push it to stack.

Finall by this line:
       while(!stack.isEmpty())

           result=result+stack.pop();

      

       System.out.println(result);
Run the same procedure upto stack is empty. When stack empty add the stack values to the results.

That's the solution, if you face any problem in this code, please make a comment.


Continue reading
Share:
Views:
Java Programming

What is Java Programming language

Tuesday, November 29, 2016 By Maniruzzaman Akash 0 Comments

Introduction to Java Programming:

Java is a computer programming language that is totally an object oriented language and which has most provably the total dependency free language.
Author : James Gosling, Mike Sheridan, and Patrick Naughton are the main inventor of this java language which basically come from an University project in June 1991. In that time, the concept was used to make a Television Cable or others help. From then it developed and Sun Microsystem are then buy it's ownership.


What is Java Programming language:

Java is a fully object oriented programming languages which comes to programming sector to make something easily or making big project like a small project and tied them into a class and use them creating a object of that class.
[Note:If you don't know all of the term I've used here, you'll be learned them after a while, don't worry.]

Features of Java programming language:

Java programming language has some features. It contains some things or objectives. Before Java programming language C++ was dominating the programming world and it had come to overcome all of the C++ term in hand and also remove all of the problems in C++. And so, Java is learning so much easy to a beginner level programmer. A programmer need not to start Java as a last programming languages. Obviously, it is more easier than C++ programming languages.

  1. Simple and small
  2. Platform independent
  3. Object Oriented
  4. Interpreted
  5. Dynamic
  6. Robust
  7. Portable
  8. Distributive
  9. Multi thread
  10. architectural neutral
  11. Web Interface
  12. High Performance
  13. Secured

For all of this features, nowadays java is one of the best choice of a programmer.


Syntax Of Java Programming Language:


public class HelloWorld{
   public static void main(String[] args)  {    
   System.out.println("Hello Everyone\nWelcome To My Blog");  
 }
}

Output of this code:

What can you do Java programming language / Java programming market price:

From all of the programming languages nowadays Java is the most used and most effectable and wanted languages in all sectors.
See the Curbe Of the programming languages demand if their are one millions of Job.





After an analysis of that curbe we can say that nowadays Java is the most demanded language over all other languages.

So, it is time for starting your java programming today.Start your java programming in my site and I promise, I'll get you some basic clear concept of Java programming language.




Continue reading
Share:
Views:
Older Posts Home
Subscribe to: Posts ( Atom )

Popular Posts

  • Numerical Methods 20 Multiple Choice Questions and Answers
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • List and briefly define two approaches to dealing with multiple interrupts
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • What are the characteristics of Digital IC's?-Solution
  • Mid Square Method Code implementation in C and MatLab
  • List and briefly define the possible states that define an instruction execution
  • BFS, DFS, DLS in Tree implementation in C
  • Download Laravel Offline Documentation as HTML
  • Simpson's 1/3 Code in Matlab

Category

Advanced PHP Android Developement Articles Artificial Intelligenece Blogger Tips Blogging Career Bootstrap Offline Documentation Bootstrap Templates C Programming Computer Architecture Data Structure Difference Between Download Documentation Download Ebook Download Free Blog Template Earning Money Electrical Electronics Guest Posts HTML Java Programming Laravel Laravel Bangla Tutorial MatLab Code My Videos MySQL Database Numerical Methods Offline Documentation Recent Topics Simulation and Modeling Unity Game Development Web Design Web Development

LIKE ME ON FACEBOOK

TAGS

  • Advanced PHP (3)
  • Android Developement (5)
  • Articles (6)
  • Artificial Intelligenece (3)
  • Blogger Tips (5)
  • Blogging Career (1)
  • Bootstrap Offline Documentation (1)
  • Bootstrap Templates (1)
  • C Programming (14)
  • Computer Architecture (5)
  • Data Structure (11)
  • Difference Between (1)
  • Download Documentation (2)
  • Download Ebook (3)
  • Download Free Blog Template (2)
  • Earning Money (1)
  • Electrical Electronics (1)
  • Guest Posts (1)
  • HTML (4)
  • Java Programming (2)
  • Laravel (3)
  • Laravel Bangla Tutorial (1)
  • MatLab Code (2)
  • My Videos (3)
  • MySQL Database (7)
  • Numerical Methods (9)
  • Offline Documentation (1)
  • Recent Topics (1)
  • Simulation and Modeling (2)
  • Unity Game Development (3)
  • Web Design (3)
  • Web Development (1)

Join Google+

Maniruzzaman Akash
View my complete profile

Join With Me

Site Visitors

Best Sites For a programmer

  • URI Online Judge Solution By Me
  • StackOverFlow
  • W3 School
  • Git Hub - Store your Every Document

Popular Posts

  • What are the characteristics of Digital IC's?-Solution
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • How to import Excel,CSV file in Laravel And insert data in database
  • List and briefly define the possible states that define an instruction execution
  • What is Blue Whale Game ? Why people suicide?
  • List and briefly define two approaches to dealing with multiple interrupts
  • ফিফা ওয়ার্ল্ড কাপ ২০১৮ শিডিউল এবং সমস্ত আপডেট- FIFA World Cup 2018 - Bangladesh Time Schedule
  • BFS, DFS, DLS in Tree implementation in C
  • Numerical Methods 20 Multiple Choice Questions and Answers

Earn Money From Your site

Translate To your language

Categories

Advanced PHP (3) Android Developement (5) Articles (6) Artificial Intelligenece (3) Blogger Tips (5) Blogging Career (1) Bootstrap Offline Documentation (1) Bootstrap Templates (1) C Programming (14) Computer Architecture (5) Data Structure (11) Difference Between (1) Download Documentation (2) Download Ebook (3) Download Free Blog Template (2) Earning Money (1) Electrical Electronics (1) Guest Posts (1) HTML (4) Java Programming (2) Laravel (3) Laravel Bangla Tutorial (1) MatLab Code (2) My Videos (3) MySQL Database (7) Numerical Methods (9) Offline Documentation (1) Recent Topics (1) Simulation and Modeling (2) Unity Game Development (3) Web Design (3) Web Development (1)

Subscribe To This Site To Get Latest Article On Programming or web

Posts
Atom
Posts
All Comments
Atom
All Comments
© 2016 Maniruzzaman Akash's Blog | All rights reserved
Developed By Maniruzzaman Akash Created By Responsive Blogger Templates | Distributed By Gooyaabi Templates