Answers
Answers
h>
#include <stdlib.h>
temp->next = newNode;
newNode->next = *head;
displayList(head);
#include <stdio.h>
#include <stdlib.h>
do { next = current-
>addr; current->addr =
prev; prev = current;
current = next; } while
(current != head);
head->addr = prev;
*head_ref = prev;
show(head);
return 0;
3.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
top++; stack[top]
= data;
char pop() { if (top == -1)
{ printf("Empty stack!\
n"); return
char data =
stack[top]; top--;
return data;
push(text[i]);
} else if (text[i] == l)' Il text[i] I] ' Il
I
text[i] } ) { if (top -1) { return 0; // If no
opening bracket is present
} else if (!
is_matching_pair(pop(), text[i]))
{ return 0; // If closing bracket doesn't
match the last opening bracket
return 0;
4.
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{ int data; struct
Node *next; } Node;
temp = temp->next;
} while (temp != head);
int main() {
Node *head = NULL;
Node *even head = NULL;
Node *odd head = NULL;
push(&head, 1 1
) push(&head, 1
0) push(&head,
8) push(&head,
6) push(&head,
4) push(&head,
2) push(&head,
0)
EvenOdd(head, &even_head,
&odd_head);
outputs
1.
2.
3.
4.
5.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Main function
int main() {
char text[MAX_SIZE];
printf("Input an expression in
parentheses: ");
scanf("%s", text);
// Check if the expression is
balanced or not
if (isBalanced(text)) {
printf("The expression is
balanced.\n");
} else {
printf("The expression is
not balanced.\n");
}
return 0;