WRITE A PROGRAM TO CREATES CIRCULAR HEADER LINKED LIST



#include<stdio.h>
#include<malloc.h>

struct list
{
    int info;
    struct list *link;
};

int i;
int number;
struct list *start, *new1;
void create_list(struct list *);
void display(struct list *);


/* Function to create a circular header linked list */

void create_list( struct list *ptr)
{
    int n;

    ptr = start;      /*ptr points to the header node */
    ptr->link = (struct list *) malloc(sizeof(struct list));
    i = 0;
    printf("\n\n\n how many nodes you want to create: ");
    scanf("%d",&n);
    printf("\n\n =======================================================\n");
    printf("\n Note That:\n -----------\n Enter numeric data in node\n");
    printf("\n =======================================================\n");
    while(i!=n)
    {
        ptr->link = (struct list* ) malloc(sizeof(struct list));
        ptr = ptr->link;
        printf("\n Enter the node %d:", (i+1));
        scanf("%d", &ptr->info);
        i++;
    }
    printf("\n\n\n------------------------\n");
    printf("\n Total nodes = %d", i);
    printf("\n\n________________________\n");
    ptr = start;
    ptr->info = i; /* Header node holds information about total nodes in list */
}



/* Function to display the list */

void display(struct list *ptr)
{
    int count;
    ptr = start;
    count = ptr->info;
    ptr = ptr->link;

    while (count>0)
    {

           printf("\n\t\t %d \n",ptr->info);
           ptr = ptr->link;
        count=count-1;
    }
}

/* Main Function */

void main()
{
    struct list *ptr = (struct list *) malloc(sizeof(struct list));
      clrscr();
    create_list(ptr);
    printf("\n------------------------\n");
    printf("\n Circular linked list :\n");
    printf("\n------------------------\n");
    display(ptr);
    getch();
}

Comments

Popular posts from this blog

Write a program to add two number using inline function in C++?

Traversing of elements program with algorithm and Flowchart