Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node{
- int x;
- struct node *next;
- }NODE;
- void printMenu() {
- printf("MENU:\n");
- printf("[1] Add number\n");
- printf("[2] Delete Number\n");
- printf("[3] Exit\n");
- printf("\n");
- }
- void addNum(NODE **head){
- NODE * new_node;
- int value;
- printf("---Add Number---\n");
- printf("Enter Number: ");
- scanf("%d", &value);
- if(head==NULL){
- new_node = (NODE*)malloc(sizeof(NODE));
- new_node -> x = value; // Gawa ng bagong node
- new_node -> next = NULL;
- new_node -> next = *head;
- *head = new_node;
- NODE *temp;
- temp = head;
- while(temp != NULL) {
- printf("%d\n", temp -> x);
- temp = temp -> next;
- }
- }else{
- if(value<new_node->x){
- new_node = (NODE*)malloc(sizeof(NODE));
- new_node -> x = value; // Gawa ng bagong node
- new_node -> next = NULL;
- new_node -> next = *head;
- *head = new_node;
- }else if(value>new_node->x){
- NODE *new_node, *last = NULL;
- last = *head;
- while(last->next!=NULL){
- // Finds the last node
- /* Habang hindi NULL ang next ng node,
- magpunta sa susunod na node */
- last = last->next;
- }
- // Ipapoint sa last node si new_node
- last->next = new_node;
- }
- }
- }
- void delNum(NODE **head){
- }
- int main(){
- NODE *head = NULL, *temp, *new_node;
- int value, choice=0;
- while(choice!=3){
- printMenu();
- printf("Enter choice: ");
- scanf("%d", &choice);
- getchar();
- if(choice==1){
- addNum(&head);//pass by ref kaya address ni head
- }else if(choice==2){
- delNum(&head);
- }else if(choice==3){
- printf("Exit.\n");
- }else{
- printf("Choose from 1-3 only.");}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement