Application of the stack in the conversion of the numeral

Source: Internet
Author: User

(unfinished: Have the time to implement this in Java, today first write the essence of the section)
The conversion of the decimal number n and the other D-numbers is the basic problem of the computer implementation, this time I will illustrate the conversion from decimal to octal code, in which the stack is used.
For example: (1348) d = (2504) o;
Description: D is decimal, O is octal
The operation process is:
n N Div 8 n mod 8
1348 168 4
168 21 0
21 2 5
2 0 2

void conversion(){    InitStack(S);    scanf("%d",N);    while(N){        Push(S,e);        N = N/8;    }    while(!StackEmpty(s)){        Pop(S,e);        printf("%d",e);    }}//conversion

Application of the stack in the conversion of the numeral

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.