-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_node_beg.c
More file actions
90 lines (90 loc) · 1.39 KB
/
delete_node_beg.c
File metadata and controls
90 lines (90 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node * next;
};
typedef struct node* nodep;
nodep create();
void display(nodep);
nodep add();
nodep del_node_beg(nodep);
int main()
{
nodep t,start;
t=add();
start=del_node_beg(t);
display(start);
getch();
return 0;
}
nodep create()
{
nodep t;
t=(nodep)malloc(sizeof(struct node));
if(t==NULL)
{
printf("stack overflow");
exit(0);
}
t->next=NULL;
printf("enter data\n");
scanf("%d",&t->info);
return t;
}
nodep add()
{
char ch;
nodep t,t1,start=NULL;
printf("Create list:\n");
do{
t=create();
if(start==NULL)
start=t;
else
t1->next=t;
t1=t;
printf("Do you want to add more(y/Y):");
scanf(" %c",&ch);
}while(ch=='y' || ch=='Y');
return start;
}
void display(nodep t)
{
if(t==NULL)
{
printf("list is empty\n");
exit(0);
}
printf("list is:");
while(t!=NULL)
{
printf("%d\t",t->info);
t=t->next;
}
}
nodep del_node_beg(nodep start)
{
nodep temp;
temp=start;
if(start==NULL)
{
printf("underflow\n");
exit(0);
}
else if(start->next==NULL)
{
start=NULL;
printf("element %d deleted\n",temp->info);
free(temp);
}
else
{
start=start->next;
printf("element %d deleted\n",temp->info);
free(temp);
}
return start;
}