Skip to main content

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

Use below command to resolve problem pip3 install PyQt5

Single Linked List code

 #include<stdio.h>

#include<stdlib.h>
#include<conio.h>
typedef struct node
{
    int data;
    struct node *next;
}node;
node *START;
int size=0;

node* createNode();
void insertAtFirst(int);
void insertAtLast(int);
void insertAtAnyPosition(int,int);
void displayNode();
void deleteLastNode();

node* createNode(){
    node *create=(node*)malloc(sizeof(node));
    return create;
}

void insertAtFirst(int data){
    node *insert;
    if(START==NULL){
        START=createNode();
        START->data=data;
        START->next=NULL;
        size++;
        printf("\n%d is inserted successfully",data);
    }
    else{
        insert=createNode();
        insert->data=data;
        insert->next=START;
        START=insert;
        size++;
        printf("\n%d is inserted successfully",data);

    }
}

void insertAtLast(int data){
    node *last,*visit;
    if(START==NULL){
        START=createNode();
        START->data=data;
        START->next=NULL;
        size++;
        printf("\n%d is inserted successfully",data);
    }
    else{
        visit=START;
        while (visit->next!=NULL)
        {
            visit=visit->next;
        }
        last=createNode();
        last->data=data;
        last->next=NULL;
        visit->next=last;
        size++;
        printf("\n%d is inserted successfully",data);

    }
}
void insertAtAnyPosition(int data,int index){
    node *position;
    node *create;
    int indexCount;
    if(index==0){
        insertAtFirst(data);
    }
    else  if(index<0 || index>size-1 ){
        if(index<0){
            printf("Invalid index");
        }
        else
           printf("\nYou can insert element b/w 0 to %d",size-1);
    }

    else {
        position=START;
        indexCount=0;
        while(indexCount<=index-2){
            position=position->next;
            indexCount++;

        }

        create=createNode();
        create->data=data;
        create->next=position->next;
        position->next=create
        printf("%d is inserted at position %d",create->data,index);
        size++;
    }
}

void displayNode()
{
    node *display;
    if(START==NULL)
        printf("No node is found,Insert your node");
    else{
        display=START;
        while(display!=NULL){
            printf("%d ",display->data);
            display=display->next;
        }
    }
}


void deleteLastNode()
{
    node *last,*secondLast;
    if(START==NULL)
        printf("No node found , Can't delete any node");
    else if(START->next==NULL){
        last=START;
        START=NULL;
        printf("Last node = %d is deleted successfully",last->data);
        free(last);
        size--;
    }
    else{
        last=START;
        while(last->next!=NULL){
            last=last->next;
        }
        secondLast=START;
        while(secondLast->next->next!=NULL)
            secondLast=secondLast->next;
        secondLast->next=NULL;
        free(last);
        size--;
        printf("Last node deleted successfully");

    }
}

int menu(){
    int choice;
    printf("\n1. Insert node as 1st node");
    printf("\n2. Insert node as Last node");
    printf("\n3. Insert node at any Position");
    printf("\n4. Display all node");
    printf("\n5. Delete last node");
    printf("\n6. Exit from program");
    printf("\nEnter your choice :");
    scanf("%d",&choice);
    return choice;
}
int main()
{
    int data,index;
    
    while(1)
    {
    // clrscr();
        system("cls");
        switch(menu()){
            case 1:
                printf("\nEnter Data to insert at first :");
                scanf("%d",&data);
                insertAtFirst(data);
                break;
            case 2:
                printf("\nEnter Data to insert at last :");
                scanf("%d",&data);
                insertAtLast(data);
                break;
            case 3:
                printf("\nEnter Data to insert at any position :");
                scanf("%d",&data);
                printf("\nEnter index value to insert at any position :");
                scanf("%d",&index);
                insertAtAnyPosition(data,index);
                break;
            case 4:
                displayNode();
                break;
            case 5:
                deleteLastNode();
                break;
            case 6:
                exit(0);
            default:
                printf("Invalid choice");
                break;
        }
        getch();
    }


}

Comments

Popular posts from this blog

Resolving Pandas problem

I used other good answers from here and didn't solve the problem (Ubuntu 18.04, Python3.8), still get this warning. Actually there is one more package is needed to be installed to solve the problem: sudo apt-get install lzma So the whole pipeline (run in the python source code folder): sudo apt-get install liblzma-dev sudo apt-get install lzma ./configure --enable-optimizations sudo make sudo make altinstall

Run C/C++ code in VSCode

  How to run C/C++ code in VSCode( Visiual Studio Code )  : Step - 1 :Download VSCode from given link below                   https://code.visualstudio.com/ Step -2 :Install VSCode after downloading Step -3 :Install C/C++ extension in VSCode as follow                i.)Click on " Extension " button                ii)Type C/C++ in search bar and install first one ,see below image Step -4 :Download " MinGW (Minimalist GNU Windows)" software from below link as follow               i) Go to  "  http://www.mingw.org/  "              ii) Click on "Downloads" option as follow                 iii)Click on given image  to download MinGW software                 iv)After Installation of MinGW software install other 2-component as follow                              a.)Select below 2-component & click on Mark for Installation                                       mingw32 base bin                                       mingw32-gcc-g++ ( Compiler )