C-Language conversion (stack implementation)

Source: Internet
Author: User
From the two blog, we can know that the stack has a last-in-first-out feature, and the output of the binary conversion is just the opposite of the computational process, to meet the stack this last-in-first-out feature, so you can use the stack to quickly implement the conversion, the following is a stack to implement the C function of the conversion
void conversion (sqstack *pstack,unsigned int N, const unsigned int d) {if (Pstack = = NULL)////When the incoming parameter is a pointer, you must empty exit ( -1); int mod ;//Save mod = n%dwhile (n! = 0) {mod = n%d;stack_push (pstack,&mod);//mod into stack N = n/d;} int top = 0;//Displays the stack top element printf ("10 binary%d to%d binary:", n,d), while (!stack_is_empty (Pstack)) {Stack_pop (pstack,&top); printf ("%d", top);} return;}

2. Results and conclusions


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C-Language conversion (stack implementation)

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.