summaryrefslogtreecommitdiff
path: root/c/dataStructure/栈和队列//链栈/p_match.c
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2022-12-05 19:43:39 +0800
committergarhve <git@garhve.com>2022-12-05 19:43:39 +0800
commitc6bc541ab58363d783e60a007e80e9bf9e231fda (patch)
treea59c7ed0d05225c5876f3e5e919d4f6ed0c447ff /c/dataStructure/栈和队列/栈/链栈/p_match.c
initialize
Diffstat (limited to 'c/dataStructure/栈和队列/栈/链栈/p_match.c')
-rwxr-xr-xc/dataStructure/栈和队列/栈/链栈/p_match.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/c/dataStructure/栈和队列/栈/链栈/p_match.c b/c/dataStructure/栈和队列/栈/链栈/p_match.c
new file mode 100755
index 0000000..44efecd
--- /dev/null
+++ b/c/dataStructure/栈和队列/栈/链栈/p_match.c
@@ -0,0 +1,41 @@
+#include "stack.h"
+
+int main(void)
+{
+ ElemType ch;
+ Stack s;
+ ElemType pop, top;
+ bool flag = true;
+
+ InitStack(&s);
+
+ while ((ch = getchar()) != '\n' && flag)
+ {
+ switch (ch)
+ {
+ case '(': Push(&s,ch);
+ break;
+ case '[': Push(&s,ch);
+ break;
+ case ')': if (StackIsEmpty(&s) || (top = GetTop(&s)) != '(')
+ flag = false;
+ else if (top == '(')
+ Pop(&s,&pop);
+ break;
+ case ']': if (StackIsEmpty(&s) || (top = GetTop(&s)) != '[')
+ flag = false;
+ else if (top == '[')
+ Pop(&s,&pop);
+ break;
+ }
+ }
+
+ if (StackIsEmpty(&s) && flag)
+ printf("Matching successful!\n\n");
+ else
+ {
+ fprintf(stderr,"Matching failed!\n\n");
+ DestroyStack(&s);
+ }
+ return 0;
+} \ No newline at end of file