TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Delete a Node at the beginning of List
Kaushik S
Nov 22
2015
Code
586
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#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