Sie sind auf Seite 1von 6

Name :Muhammad Muneeb

Roll no. BSEM-F19-200


Section :3D

include <iostream>

using namespace std;

struct node

int data;

node *next;

};

class list

private:

node *head, *tail;

public:

list()

head=NULL;

tail=NULL;

void createnode(int value)

{
node *temp=new node;

temp->data=value;

temp->next=NULL;

if(head==NULL)

head=temp;

tail=temp;

temp=NULL;

else

tail->next=temp;

tail=temp;

void display()

node *temp=new node;

temp=head;

while(temp!=NULL)

cout<<temp->data;

temp=temp->next;

}
}

void insertfirst(int value)

node *temp=new node;

temp->data= value;

temp->next=head;

head=temp;

void inser_position(int pos, int value)

node *pre=new node();

node *cur=new node();

node *temp= new node();

cur=head;

for(int i=1; i<pos; i++)

pre=cur;

cur=cur->next;

temp->data=value;

pre->next=temp;

temp->next=cur;

}
void delete_position(int pos)

node *pre=new node();

node *cur=new node();

//node *temp= new node();

cur=head;

for(int i=1; i<pos; i++)

pre=cur;

cur=cur->next;

//temp->data=value;

//pre->next=temp;

//temp->next=cur;

pre->next=cur->next;

void deletefirst()

node *pre=new node();

node *cur=new node();

node *temp=new node();

cur=head;

for(int i=1; i<pos; i++)


{

pre=cur;

cur=cur->next;

temp->data=value;

pre->next=temp;

temp->next=cur;

};

int main()

list obj;

obj.createnode(1);

obj.createnode(2);

obj.createnode(3);

obj.createnode(4);

obj.createnode(5);

obj.createnode(6);

obj.createnode(7);

obj.createnode(8);

obj.display();

cout<<"insert at first"<<endl;

obj.insertfirst(100);

obj.display();

cout<<"insert at any position"<<endl;


obj.inser_position(3,1000);

obj.display();

cout<<"delete at any position"<<endl;

obj.delete_position(3);

obj.display();

cout<<"delete at first position"<<endl;

obj.deletefirst();

obj.display();

return 0;

Das könnte Ihnen auch gefallen