当前位置:网站首页>Stack application (balancer)
Stack application (balancer)
2022-07-03 13:33:00 【fitpolo】
explain : Is based on the previous chapter ,C Language realizes the basic functions of stack .
Stack code
symbol_match.h
#ifndef __SYMBOL_MATCH_C__
#define __SYMBOL_MATCH_C__
extern int scanner(const char *code);
#endif
symbol_match.c
#include "symbol_match.h"
#include "link_stack.h"
static int is_left(char c)
{
int ret = 0;
switch(c)
{
case '<':
case '(':
case '[':
case '{':
case '\'':
case '\"':
ret = 1;
break;
default:
ret = 0;
break;
}
return ret;
}
static int is_right(char c)
{
int ret = 0;
switch(c)
{
case '>':
case ')':
case ']':
case '}':
case '\'':
case '\"':
ret = 1;
break;
default:
ret = 0;
break;
}
return ret;
}
static int match(char left, char right)
{
int ret = 0;
switch(left)
{
case '<':
ret = (right == '>');
break;
case '(':
ret = (right == ')');
break;
case '[':
ret = (right == ']');
break;
case '{':
ret = (right == '}');
break;
case '\'':
ret = (right == '\'');
break;
case '\"':
ret = (right == '\"');
break;
default:
ret = 0;
break;
}
return ret;
}
int scanner(const char *code)
{
int ret = 0;
int i=0;
char *c;
link_stack *head;
head = link_stack_create();
while(code[i] != '\0')
{
// printf("%c",code[i]);
if ( is_left(code[i]))
{
link_stack_push(head,(void*)&code[i]);
}
if ( is_right(code[i]))
{
c = link_stack_pop(head);
if (c==NULL || !match(c[0],code[i]))
{
printf("%c does not match!\n", code[i]);
ret = 0;
break;
}
}
i++;
}
if ( 0==link_stack_size(head) && code[i]=='\0')
{
printf("Succeed!\n");
ret = 1;
} else
{
printf("Invalid code!\n");
ret = 0;
}
link_stack_destroy(head);
return ret;
}
Test code
#include "stdio.h"
#include "stdint.h"
#include "symbol_match.h"
int main(void)
{
//#define BUF_SIZE 10
// int i;
// int buf[BUF_SIZE];
// int *int32_tmp;
//const char* code = "#include <stdio.h> int main() { int a[5][5]; int (*p)[4]; p = a[0]; printf(\"%d\\n\", &p[3][3] - &a[3][3]); return 0; }";
const char* code = "{}[][]asdggggggggg<>()hhhhhhhh[][iiiiiiiiiiiii]";
printf("hello\n");
scanner(code);
}
边栏推荐
- (first) the most complete way to become God of Flink SQL in history (full text 180000 words, 138 cases, 42 pictures)
- Flink code is written like this. It's strange that the window can be triggered (bad programming habits)
- Detailed explanation of multithreading
- Flink SQL knows why (XV): changed the source code and realized a batch lookup join (with source code attached)
- Flick SQL knows why (10): everyone uses accumulate window to calculate cumulative indicators
- Flutter动态化 | Fair 2.5.0 新版本特性
- 刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
- Ubuntu 14.04 下开启PHP错误提示
- Red Hat Satellite 6:更好地管理服务器和云
- mysql更新时条件为一查询
猜你喜欢

常见的几种最优化方法Matlab原理和深度分析

MySQL installation, uninstallation, initial password setting and general commands of Linux

Multi table query of MySQL - multi table relationship and related exercises

TensorBoard可视化处理案例简析

Complete deep neural network CNN training with tensorflow to complete picture recognition case 2

Flink SQL knows why (13): is it difficult to join streams? (next)

Flink SQL knows why (VIII): the wonderful way to parse Flink SQL tumble window
![[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]](/img/95/09552d33d2a834af4d304129714775.png)
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]

这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看

Flink SQL knows why (XI): weight removal is not only count distinct, but also powerful duplication
随机推荐
Tutoriel PowerPoint, comment enregistrer une présentation sous forme de vidéo dans Powerpoint?
MySQL installation, uninstallation, initial password setting and general commands of Linux
Students who do not understand the code can also send their own token, which is easy to learn BSC
Universal dividend source code, supports the dividend of any B on the BSC
Several common optimization methods matlab principle and depth analysis
Kivy tutorial how to load kV file design interface by string (tutorial includes source code)
Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
常见的几种最优化方法Matlab原理和深度分析
Task5: multi type emotion analysis
Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
stm32和电机开发(从mcu到架构设计)
显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
pytorch 载入历史模型时更换gpu卡号,map_location设置
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
MySQL constraints
Red hat satellite 6: better management of servers and clouds
106. How to improve the readability of SAP ui5 application routing URL
Red Hat Satellite 6:更好地管理服务器和云