Created
February 22, 2026 09:10
-
-
Save raiyansarker/8eb91d9c0eae4c603dc69257e9d69e61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| typedef struct Node { | |
| int data; | |
| struct Node *next; | |
| } Node; | |
| void push(Node **head, int data); | |
| int pop(Node **head); | |
| int peak(Node *head); | |
| int main() { | |
| Node *head = NULL; | |
| push(&head, 1); | |
| push(&head, 2); | |
| push(&head, 5); | |
| push(&head, 3); | |
| printf("Peak %d\n", peak(head)); | |
| printf("%d\n", pop(&head)); | |
| printf("%d\n", pop(&head)); | |
| printf("Peak %d\n", peak(head)); | |
| printf("%d\n", pop(&head)); | |
| printf("%d\n", pop(&head)); | |
| printf("%d\n", pop(&head)); | |
| return 0; | |
| } | |
| void push(Node **head, int data) { | |
| Node *new = (Node*)malloc(sizeof(Node)); | |
| new->data = data; | |
| new->next = *head; | |
| *head = new; | |
| } | |
| int pop(Node **head) { | |
| if (*head == NULL) return -1; | |
| Node *t = *head; | |
| int val = t->data; | |
| *head = t->next; | |
| free(t); | |
| return val; | |
| } | |
| int peak(Node *head) { | |
| if (head == NULL) return -1; | |
| return head->data; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment