Ds New Input 5
Ds New Input 5
h>
#include <stdlib.h>
struct Node {
int data;
};
void push(struct Node** top_ref, int new_data) {
struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
if (new_node == NULL) {
printf("Stack Overflow\n");
return;
}
new_node->data = new_data;
new_node->next = (*top_ref);
(*top_ref) = new_node;
if (*top_ref == NULL) {
printf("Stack Underflow\n");
return -1;
}
struct Node* temp = *top_ref;
*top_ref = temp->next;
free(temp);
return popped_data;
if (top == NULL) {
printf("Stack is empty\n");
return -1;
}
return top->data;
if (top == NULL) {
printf("Stack is empty\n");
return;
temp = temp->next;
}
printf("\n");
int main() {
push(&stack, 10);
push(&stack, 20);
push(&stack, 30);
traverse(stack);
traverse(stack);
return 0;