Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct node {
- int val;
- struct node * next;
- } node_t;
- void print(node_t * head) {
- node_t * current = head;
- while (current != NULL) {
- printf("%d\n", current->val);
- current = current->next;
- }
- }
- void menu(node_t *head) {
- int n;
- printf("What operation do you want to execute?\n");
- printf("Press 1 to print all elements.\n");
- printf("Press 0 to exit.\n");
- scanf("%d", &n);
- switch(n) {
- case 1:
- print(head);
- break;
- }
- if (n!=0) menu(head);
- }
- int main() {
- node_t *head = NULL;
- head = malloc(sizeof(node_t));
- int num;
- printf("Enter the first integer: ");
- scanf("%d", &num);
- head->val = num; // head er address e jei node ta ache tar val er man rakhlam num
- head->next = NULL; // porer address hishebe rakhlam NULL. orthat ekhanei shes
- menu(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement