Question: Given the following code as a whole, can someone please help me split it up into the following files correctly, without changing the functionality at

Given the following code as a whole, can someone please help me split it up into the following files correctly, without changing the functionality at all and making sure everything still works when compiled? I am trying but I can't get the order/functions/declarations right when I split them into different files.

Split into:

main.c (containing the main function)

stack.c (containing the pop and push functions)

stack.h (don't even know what to put here)

balance.c (containing checkBalance and checkMatching functions)

-----------------------------------------------------------------------------------------------------------

#include #include

struct node { char data; struct node *next; };

void push(struct node **start, int newData); int pop(struct node **start);

int checkMatching(char char1, char char2) { if (char1 == '(' && char2 == ')') return 1; else if (char1 == '{' && char2 == '}') return 1; else if (char1 == '[' && char2 == ']') return 1; else return 0; }

int checkBalance(char str[]) { int i = 0; struct node *stack = NULL; while (str[i]) { if (str[i] == '{' || str[i] == '(' || str[i] == '[') push(&stack, str[i]); if (str[i] == '}' || str[i] == ')' || str[i] == ']') { if (stack == NULL) return 0; else if (!checkMatching(pop(&stack), str[i])) return 0; } i++; } if (stack == NULL) return 1; else return 0; } int main() { char str[300]; int i; int j; scanf("%d",&j); getchar(); for(i=0;i { fgets(str, sizeof str, stdin); if(str[0]==' ') { printf("Yes "); } else if (checkBalance(str)) printf("Yes "); else printf("No "); } return 0; }

void push(struct node **start, int newData) { struct node *temp = (struct node*) malloc(sizeof(struct node)); if (temp == NULL) { printf("Stack overflow "); getchar(); exit(0); } temp->data = newData; temp->next = *start; *start = temp; }

int pop(struct node **start) { char res; struct node *top; if (*start == NULL) { printf("Stack overflow "); getchar(); exit(0); } else { top = *start; res = top->data; *start = top->next; free(top); return res; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!