[C / C ]Stack and applications- Stack trong C – Stack in C
Stack is an unordered list that allows insertion and deletion is performed at the end of the list and we call this the tip end (top) the stack.
Here is the code and also a number of operations performed by C Stack
#include <stdlib.h> #include <stdio.h> #include <stack> //khai bao Stack using namespace std; int main() { stack <int> S; //Khai bao Stack for (int x=0; x<10; x++) //Nhap Stack S.push(x*2); //Them phan tu vao Stack printf("nDo dai Stack: %d n",S.size()); //Do dai Stack while(!S.empty()) //Trong khi danh sach khong rong thi duyet va xuat ra Stack { int x = S.top(); //lay gia tri Top S.pop(); //Loai bo phan tu Top printf("%d ",x); //Xuat ra Stack } return 0; }
Application Stack
Stack has many applications in information technology as :
– Convert the number (Binary, decimal, octal,…)
– Jump infix expression to postfix, calculate the expression suffix,…
Now we will learn and installation 2 problem on
– Jump base: The following code will transfer the base 10 to base x keyboard input
#include <stdlib.h> #include <stdio.h> #include <stack> //khai bao Stack using namespace std; int main() { stack <int> S; int coso, so, du, n; printf("Nhap so can chuyen: "); scanf("%d",&so); n = so; printf("Nhap co so can chuyen: "); scanf("%d",&coso); while(so) { du = so % coso; S.push(du); so /= coso; } printf ("So %d trong he %d la : ", so, coso); while(!S.empty()) { printf("%d",S.top()); S.pop(); } return 0; }
you / your household listed dear brother / her tasks related to stack and queue with
You see here nehs
https://www.cachhoc.net/2014/12/29/lap-trinh-c-bai-15-cai-dat-ngan-xep-stack/
What about my friend “Jump infix expression to postfix, calculate the expression suffix,...” Where is it, sir??
You see turning infix to suffix here nhé
https://www.cachhoc.net/2013/07/07/thuat-toan-java-chuyen-bieu-thuc-trung-to-sang-hau-to-java-converts-infix-to-postfix/
His plan fails, then !!!
What goes where so you?
there is a code C application stack on math test K a valid brackets
He did not nhưn thought is put into the closed sign, when meeting point will open the corresponding check mark.
Bro, there is C ++ code that uses stack and queue to convert real numbers with integers 0 (0.2435) to binary a?
There are examples in this article, You develop yourself.