Algorithm for inserting a node at the Beginning in Circular linked list


Step 1: Check for Overflow 
           if ptr = Null then 
              print overflow
              Exit 
           else
              ptr = (node *) malloc (size of (node));
        End if
Step 2: if start = Null then
           set ptr -> num = item
           set ptr -> next = ptr
           start = ptr
           last = ptr
        End if
Step 3: set ptr -> num = item 
Step 4: set ptr -> next = start 
Step 5: set start = ptr 
Step 6: set last -> next = ptr 
Step 7: EXIT

Program

insert-beg (node * start)
{
  p= (node*) malloc (size of (node));
  print("Enter the Number");
  scanf("%d", & p -> num);
  if (start == NULL)
  {
	p -> next = p;
	start = p;
	last = p;
  }
  else
    p -> next = start;
    start = p;
    last -> next = p;
}