Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Bounty
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Delete a Node at the beginning of List
WhatsApp
Kaushik S
Nov 22
2015
621
0
0
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
typedef
struct
node{
int
data;
struct
node* next;
}node;
struct
node* head;
void
insertatbeginning(
int
x)
{
struct
node* temp=NULL;
temp=(node*)malloc(
sizeof
(
struct
node));
temp->data=x;
if
(head==NULL)
{
head=temp;
temp->next=NULL;
}
else
{
temp->next=head;
head=temp;
}
}
void
print()
{
struct
node* temp=head;
while
(temp!=NULL)
{
printf(
"%d"
,temp->data);
temp=temp->next;
}
}
void
DeleteFirstNode()
{
struct
node* temp=head;
struct
node* temp2=NULL;
temp2=temp->next;
head=temp2;
free(temp);
printf(
" After Deleting "
);
print();
}
void
main()
{
insertatbeginning(1);
insertatbeginning(2);
insertatbeginning(3);
insertatbeginning(4);
print();
DeleteFirstNode();
getch();
}
C
Datastructures
Node at the beginning of List
Up Next
Delete a Node at the beginning of List