Please solve it in c Design a linked list class named Intege

Please solve it in c++

Design a linked list class named IntegerList to hold a series of integers. The class must have public member functions for appending, inserting, deleting and displaying nodes. The append function must append a node to the end of the list. The insert function must insert node in ascending order. The delete function must delete the node with the given value. The display function should display the list from head to tail. The IntegerList class should also have a destructor that destroys the list and release memory. The list node must be declared as a structure using keyword struct. This structure is a private member of IntegerList. You should also store the head of the list as a private member. Write a test program to test the implementation your IntegerList class works properly. Add a member function to the IntegerList class to insert a node by position. The new insert function signature should be as follow, void insertByPosition(int value, int pos) where pos denotes the position in the list where the value should be inserted. A pos value of 0 means the node will be inserted at the front of the list. A pos value of 1 means the node will be inserted in the second position in the list. A pos value of equal to or greater than the length of the list means the node will be inserted at the end of the list. If the list is empty, the node will be inserted at the beginning of the list. Write a test program to test the implementation of your new function works properly.

Solution


#include<stdio.h>
#include<stdlib.h>

struct list_Node
{
int data;
struct list_Node *next;
}*first=NULL;

void insert()
{
struct list_Node *t;//t=temp
structlist_Node *nn=(struct list_Node*)malloc(sizeof(struct list_Node));
printf(\"enter the data\ \");
scanf(\"%d\",&n->data);
t=first;
while(t->next!=first)
    t=t->next;
t->next=nn;
n->next=NULL;
}

void display()
{
struct list_Node *t;
t=first;
if(t==NULL)
{
    printf(\"no elements\ \");
    return;
}
printf(\"elements in linked list are\ \");
while(t!=NULL)
{
    printf(\"%d\ \",t->data);
    t=t->next;
}
}

void deletion()
{
struct list_Node *t;
t=first;
first=first->next;
t->next=NULL;
free(t);
}

int main()
{
int op;
do
{
    printf(\"1.insertion\ 2.deletion\ 3.display\ 4.exi\ \");
    printf(\"enter option\ \");
    scanf(\"%d\",&op);
    switch(op)
    {
      case 1:insert();
             break;
      case 2:deletion();
             break;
      case 3:display();
             break;
    }
}while(op!=6);
}


it is a c code for inserting deleting and appending nodes in linked list

Please solve it in c++ Design a linked list class named IntegerList to hold a series of integers. The class must have public member functions for appending, ins
Please solve it in c++ Design a linked list class named IntegerList to hold a series of integers. The class must have public member functions for appending, ins

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site