-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha14f4.c
More file actions
105 lines (90 loc) · 1.95 KB
/
Copy patha14f4.c
File metadata and controls
105 lines (90 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int StackElementType;
typedef struct StackNode *StackPointer;
typedef struct StackNode
{
StackElementType Data;
StackPointer Next;
} StackNode;
typedef enum {
FALSE, TRUE
} boolean;
void CreateStack(StackPointer *Stack);
boolean EmptyStack(StackPointer Stack);
void Push(StackPointer *Stack, StackElementType Item);
void Pop(StackPointer *Stack, StackElementType *Item);
int main() {
StackPointer AStack;
StackElementType AnItem;
int n,i;
char str[40];
boolean found = TRUE;
CreateStack(&AStack);
printf("EISAGETE MIA PARASTASI: ");
scanf("%s",str);
for(i = 0; i<strlen(str); i++)
{
if(str[i]=='{' || str[i]=='(' || str[i] == '[')
Push(&AStack, str[i]);
else if (str[i]=='}' || str[i]==')' || str[i] == ']')
{
if(EmptyStack(AStack)){
found=FALSE;
break;
}
else
{
Pop(&AStack, &AnItem);
if(str[i]=='}' && AnItem!='{')
{
found=FALSE;
break;
}else if(str[i]==')' && AnItem!='(')
{
found=FALSE;
break;
}if(str[i]==']' && AnItem!='[')
{
found=FALSE;
break;
}
}
}
}
if(found==FALSE || !(EmptyStack(AStack))){
printf("WRONG\n");
}else printf("CORRECT\n");
return 0;
}
void CreateStack(StackPointer *Stack)
{
*Stack = NULL;
}
boolean EmptyStack(StackPointer Stack)
{
return (Stack==NULL);
}
void Push(StackPointer *Stack, StackElementType Item)
{
StackPointer TempPtr;
TempPtr= (StackPointer)malloc(sizeof(struct StackNode));
TempPtr->Data = Item;
TempPtr->Next = *Stack;
*Stack = TempPtr;
}
void Pop(StackPointer *Stack, StackElementType *Item)
{
StackPointer TempPtr;
if (EmptyStack(*Stack)) {
printf("EMPTY Stack\n");
}
else
{
TempPtr = *Stack;
*Item=TempPtr->Data;
*Stack = TempPtr->Next;
free(TempPtr);
}
}