Skip to content

Instantly share code, notes, and snippets.

@cypok
Forked from anonymous/main.c
Created Mar 30, 2012
Embed
What would you like to do?
Феерическое прухло
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "stack.h"
int check(char* expression){
int i;
for(i=0; i<= strlen(expression); i++){
if(expression[i]=='(')
{
push('(');
}
else if(expression[i]==')')
{
is_empty();
pop('(');
}
if(expression[i]=='{')
{
push('{');
}
else if(expression[i]=='}')
{
is_empty();
pop('{');
}
if(expression[i]=='[')
{
push('[');
}
else if(expression[i]==']')
{
is_empty();
pop('[');
}
}
is_empty();
}
void test(void){
assert(check(""));
assert(check("()"));
assert(check("()()"));
assert(check("(())"));
assert(check("{}"));
assert(check("{}{}"));
assert(check("{{}}"));
assert(check("[]"));
assert(check("[][]"));
assert(check("[[]]"));
assert(check("{[]}"));
assert(check("([{}])"));
assert(check("[{{{()}}}]"));
assert(check("([{()}])"));
assert(!check(")("));
assert(!check("("));
assert(!check(")"));
assert(!check("}{"));
assert(!check("{"));
assert(!check("}"));
assert(!check("]["));
assert(!check("["));
assert(!check("]"));
assert(!check("(()"));
assert(!check("())"));
assert(!check("{{}"));
assert(!check("{}}"));
assert(!check("[[]"));
assert(!check("[]]"));
assert(!check("{)"));
assert(!check("({])"));
assert(!check("{[({)]}"));
assert(!check("[({)]"));
assert(!check("[(}]"));
assert(!check("{{[}}"));
}
int main(void){
test();
clean_stack();
return 0;
}
#include <stdio.h>
#include <assert.h>
char values[100];
int index=0;
int push(char c){
c = values[index++];
}
int pop(char c){
if(index>0)
{
c = values[--index];
}
else if(index<0)
{
return 0;
}
}
int is_empty(void){
return index==0;
}
int clean_stack(void){
index=0;
}
#pragma once
int push(char c);
int pop(char c);
int is_empty(void);
int clean_stack();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment