Professional Documents
Culture Documents
Practical Number 10 Dsu
Practical Number 10 Dsu
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
}
};
struct node *end(struct node **p,int value)
{
struct node *new_node=new node;
new_node->data=value;
new_node->next=NULL;
if(*p==NULL)
{
*p=new_node;
}
struct node *last=*p;
while(last->next!=NULL)
{
last=last->next;
}
last->next=new_node;
};
void print(struct node *k)
{
while(k!=NULL)
{
cout<<k->data<<endl;
k=k->next;
}
}
void deletenode(struct node **head_re,int key)
{
struct node *temp=*head_re,*prev;
if(temp !=NULL&&temp->data==key)
{
*head_re=temp->next;
free(temp);
return;
}
}
int main()
{
struct node *head=NULL;
first(&head,58);
first(&head,96);
first(&head,23);
print(head);
after(head->next->next,888);
after(head,999);
cout<<"add after \n";
print(head);
end(&head,2362);
end(&head,8956);
cout<<"\nadd at end:\n";
print(head);
deletenode(&head,23);
cout<<"\n\n";
print(head);
}