Algo & Program to Create and Traverse a Linked List

Program to create a Linked List in C

#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node *next;
};
struct node *head=NULL;
struct node* createNode(){
    struct node *newNode = (struct node *)malloc(sizeof(struct node));
    return (newNode);
}
int menu(){
    int choice;
    printf(" 1. Create Node");
    printf("\n 2. exit");
    printf("\n Please enter your choice: \t");
    scanf("%d",&choice);
    return(choice);
}   
void main(){
    while(1){
        switch(menu()){
            case 1:
                createNode();
                printf("Node Created Successfully \n \n");
                break;
            case 2:
                exit(0);
            default:
                printf("Invalid choice");
        }
        getch();
    }
}

Output:

program to create a linked list

[wpusb]