ProAnswers.org

algorithm Creating a linked list of n nodes

algorithm for Creating a linked list of n nodes

typedef struct node{

	    int data;

	    struct node *next;

	}node;

	 

	/* This function creates a

	   link list of n nodes */

	 

	node *create(int n){

	    int i;

	    node *head, *move, *link;

	    head = (node *)malloc(sizeof(node));

	    scanf("%d", &(head->data));

	    head->next = NULL;

	    move = head;

	    for(i=1;i

	        link = (node *)malloc(sizeof(node));

	        scanf("%d", &(link->data));

	        link->next = NULL;

	        move->next = link;

	        move = move->next;

	    }

	    return head;

	}