Data structure and algorithm analysis java--stack and queue 1

Source: Internet
Author: User

1. Stack

1.1 Classification

Sequential stacks: implementation of sequential linear tables

Chained stacks: one-way linked list storage stack

1.2 Stacks of applications

1) The conversion of the numeral

ImportJava.util.Scanner;ImportJava.util.Stack; Public classtran{ Public Static voidMain (String arg[]) {Scanner y=NewScanner (system.in); System.out.println ("Please enter a decimal number"); intb=Y.nextint (); Tran J=NewTran ();      J.erjinzhi (b);      J.bajinzhi (b);     J.shiliujinzhi (b); }   // Convert to Binary   voidErjinzhi (inta) {Stack<Integer> s=NewStack<integer>(); String Str="";  while(a>0) {S.push (a%); A=a/2; }      while(!S.isempty ()) {STR=str+S.pop (); } System.out.println ("Binary is" +str); }    //Convert to eight-step system   voidBajinzhi (inta) {Stack<Integer> s=NewStack<integer>(); String Str="";  while(a>0) {S.push (a%8); A=a/8; }      while(!S.isempty ()) {STR=str+S.pop (); } System.out.println ("Octal is" +str); }   //Convert to hexadecimal   voidShiliujinzhi (inta) {    intC=0; String Str=""; Stack<Character> s=NewStack<character>();  while(a>0) {C=a%16; Switch(c) { Case(Ten): S.push (' A '); Break;  Case(one): S.push (' B '); Break;  Case(a): S.push (' C '); Break;  Case(a): S.push (' D '); Break;  Case(+): S.push (' E '); Break;  Case(a): S.push (' F '); Break; default: S.push ((Char) (a%16+48)); } A=a/16; }     while(!S.isempty ()) {STR=str+S.pop (); } System.out.println ("Hex is" +str); } }
View Code

2) Conversion of expressions

Infix expression: a+b*c; prefix-expression: +A*BC; Suffix expression: acb*+

Data structure and algorithm analysis java--stack and queue 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.