-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbf9466
commit ec560a3
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |