Skip to content

Commit

Permalink
Deletion at head of linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilatkan committed Feb 20, 2020
1 parent bbf9466 commit ec560a3
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions LLdeletionathead.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<iostream>
using namespace std;
class node
{
public:
int data;
node *next;

node(int d)
{
data=d;
next=NULL;
}
};




void insertathead(node*&head,int data)
{
node*n=new node(data);
n->next=head;
head=n;
}

void deletionathead(node*&head)
{
if(head==NULL)
{
return ;
}
node*temp=head;
head=head->next;
delete temp;
}




void print(node*head)
{
while(head!=NULL)
{
cout<<head->data<<"->";
head=head->next;
}
}

int main()
{
node*head=NULL;
insertathead(head,5);
insertathead(head,6);
insertathead(head,7);
insertathead(head,2);
deletionathead(head);
print(head);

return 0;


}

0 comments on commit ec560a3

Please sign in to comment.