Answer to Question #276200 in Databases | SQL | Oracle | MS Access for Yash

Question #276200

1. Insert a node at beginning



2. Insert a node at end



3. Delete a node from beginning



4. Delete a node from end



5. Count number of nodes in Circular linked



list

1
Expert's answer
2021-12-06T16:43:38-0500
#include<stdio.h>
#include<stdlib.h>

struct node  
{
    int data;
    struct node *rnext;
    struct node*lnext;
}*first=NULL,*last=NULL;

void  display()
{
    struct node*temp;

    if(first==NULL)
    {
        printf("list is empty\n");
        return;
    }

    temp=first;

    while(temp!=NULL)
    {
        printf("%d \n",temp->data);
        temp=temp->rnext;
    }
}

void  insertion()
{
    struct node *temp;
    struct node *nn= (struct node*) malloc(sizeof(struct node));
    printf("enter data to be inserted\n");
    nn->rnext=NULL;
    last->rnext=nn;
    nn->lnext=last;
    last=nn;
}

void deletion()
{
    struct node *temp;

    if(first==NULL||last==NULL)
    {
        printf("list is empty\n");
        return;
    }

    temp=first;
    first=first->rnext;
    first->lnext=NULL;
    free(temp);
}

/* main loop */

int  main()    
{
    int option;
    do
    {
        printf("enter option 1.insertion\n2.display\n3.deletion\n4.exit\n");
        scanf("%d",&option);
        switch(option)
        {
            case 1:
                insertion();
                break;
            case 2:
                display();
                break;
            case 3:
                deletion();
                break;
        }
    } while(option!=4);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS