हिंदी माध्यम नोट्स
Categories: C Language in hindi
Linked List : deleting in c language in hindi , लिंक लिस्ट में डिलीटिंग या डिलीट क्या होता है c कंप्यूटर भाषा हिंदी में
लिंक लिस्ट में डिलीटिंग या डिलीट क्या होता है c कंप्यूटर भाषा हिंदी में Linked List : deleting in c language in hindi :-
deleting operation , inserting operation से easy होता है |केवल एक pointer value ही change करना होता है | deleting operation तीन प्रकार से होता है :-
1.Deleting first element
2.Deleting last element
3.Deleting middle element
linked list मे deleting algorithm है :-
if the list empty होती तब
node डिलीट नहीं होता है |
else
अगर node first node हो तब
head , second node को point करता है |
else
node list की body मे से डिलीट होता है |
जिस भी node को डिलीट करते है उसके लिए allocate memory space को भी free करना होता है |insertion की तरह डिलीट operation मे भी किसी node को search करके डिलीट कर सकते है |
1.delete first node
इस source code मे linked list के first node को डिलीट किया जाता है |सबसे पहले linked लिस्ट को create किया जाता है उसके बाद data insert किया जाता है |और बाद मे first element को डिलीट किया किया है |
#include <stdio.h>
#include <stdlib.h>
#includ<conio.h>
struct employee {
int salary; // salary
struct employee *address; // Address
} *h;
void create_list(int n);
void delete_firstnode();
void display_list();
int main()
{
int num, c;
printf(“Enter nodes number : “);
scanf(“%d”, &num);
create_list(num);
printf(“\n linked list salary \n”);
display_list();
printf(“\n Enter ‘1’ for delete first node of linked list : “);
scanf(“%d”, &c);
delete_list();
printf(“\n salary in linked list \n”);
display_list();
getch(0);
}
void create_list(int n)
{
struct employee *addnode, *t;
int s, i;
h = (struct employee *)malloc(sizeof(struct employee));
if(h == NULL)
{
printf(“no more space “);
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
h->salary = s; // assign the user inpur salary into salary field of ‘h’
h->address = NULL; // assign null to address field of ‘h’
t = h;
for(i=2; i<=n; i++)
{
addnode = (struct employee *)malloc(sizeof(struct employee));
if(addnode == NULL)
{
printf(” No more space “);
break;
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
addnode->salary = s; // assign the user input salary into salary field of new node
addnode->address = NULL; // assign null to address field of new node
t->address = addnode; // node linking mean make a link between t or addnode
t = t->address;
}
}
}
}
void delete_firstnode()
{
struct employee *del;
if(h == NULL)
{
printf(“List is empty.”);
}
else
{
del = h;
h = h->address;
printf(“\n salary delete = %d\n”, del->salary);
free(del);
printf(“first node deleted \n”);
}
}
void display_list()
{
struct employee *t;
if(h == NULL)
{
printf(“List is already empty .”);
}
else
{
t = h;
while(t != NULL)
{
printf(“salary = %d\n”, t->salary);
t = t->address;
}
}
}
इस code मे ,
employee एक structure type data type है जो की linked लिस्ट के एक node को show करता है |
void create_list(int n): इस function का use linked लिस्ट को create करने के लिए किया जाता है |
void delete_firstnode():इस function का use linked लिस्ट के first element को delete करने के लिए किया जाता है |
void display_list():इस function का use , linked लिस्ट के सभी item को display करने के लिए किया जाता है |
void create_list() और void display_list () function को हम पहले creating और inserting operation मे पढ़ चुके है |अतः हम इस article मे केवल delete operation को पढेगे |
void delete_firstnode()
इस function मे ,
सबसे पहले ,एक pointer variable ‘del’ को declare करेगे |
फिर condition को check करगे ,अगर head node empty है तब empty linked लिस्ट का message show हो जाये गा |
अगर नहीं होता तब h के address को del pointer मे assign कर देते है और h के address field को ‘h’ के address को assign कर देते है जिससे head node ,first node को छोड कर उसके age node को point करता है |
Deleting last element
इस source मे केवल मुख्य डिलीट operation के code को लिखा गया क्योकि create और display और main() function deleting last node के समान होगा |इसका code है :-
void delete_lastnode()
{
struct node *del, *lastnode;
if(h == NULL)
{
printf(“Empty Linked list “);
}
else
{
del = h;
lastnode = h;
/* set complier to the last node of the list */
while(del->address != NULL)
{
lastnode = del;
del = del->address;
}
if(del == h)
{
h = NULL;
}
else
{
/* delete link of second last node with last node */
lastnode->address = NULL;
}
/* Delete the last node */
free(del);
}
}
इस प्रोग्राम मे , दो pointer variable को declare किया गया है :-
1.del : जो की डिलीट किये जाने वाले node के address को contain करता है |
2.lastnode:इस pointer variable मे भी del का address store होता है |
सबसे पहले del और lastnode को head pointer variable ‘h’ के address से initial करते है |
उसके बाद while loop जब तक चलाया जाता है तब तक del का address null नहीं हो जाता है |
while loop की body मे ,
1.सबसे पहले lastnode मे del के address को assign किया जाता है |
2.del pointer मे ‘del’ यानि head ‘h’ का address field मे store address को assign किया जाता है |
जैसे ही del के address मे null pointer आ जाता है उस समय last node मे del का address store होता है और del मे list के last node का address होता है |
फिर condition को check किया जाता है :-
अगर ‘del’ और ‘h’ की value same होती है तब लिस्ट मे एक ही node होता है|और ‘h’ को null set करने से linked लिस्ट का node डिलीट हो जाता है |
अगर same नहीं होती तब last node का address field मे null pointer assign हो जाता है जिससे की del का node डिलीट हो जाता है |
Delete Entire Linked list
#include <stdio.h>
#include <stdlib.h>
#includ<conio.h>
struct employee {
int salary; // salary
struct employee *address; // Address
} *h;
void create_list(int n);
void delete_list();
void display_list();
int main()
{
int num, c;
printf(“Enter nodes number : “);
scanf(“%d”, &num);
create_list(num);
printf(“\n linked list data \n”);
display_list();
printf(“\n Enter ‘1’ for delete linked list : “);
scanf(“%d”, &c);
delete_list();
printf(“\n Data in linked list \n”);
display_list();
getch(0);
}
void create_list(int n)
{
struct employee *addnode, *t;
int s, i;
h = (struct employee *)malloc(sizeof(struct employee));
if(h == NULL)
{
printf(“no more space “);
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
h->salary = s; // assign the user inpur salary into salary field of ‘h’
h->address = NULL; // assign null to address field of ‘h’
t = h;
for(i=2; i<=n; i++)
{
addnode = (struct employee *)malloc(sizeof(struct employee));
if(addnode == NULL)
{
printf(” No more space “);
break;
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
addnode->salary = s; // assign the user input salary into salary field of new node
addnode->address = NULL; // assign null to address field of new node
t->address = addnode; // node linking mean make a link between t or addnode
t = t->address;
}
}
}
}
void delete_list()
{
struct employee *t;
while(h != NULL)
{
t = h;
h = h->address;
free(t);
}
printf(” linked list delete \n”);
}
void display_list()
{
struct employee *t;
if(h == NULL)
{
printf(“List is already empty .”);
}
else
{
t = h;
while(t != NULL)
{
printf(“salary = %d\n”, t->salary);
t = t->address;
}
}
}
इस प्रोग्राम से , किसी linked list के सभी data को डिलीट करना होता है |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
1 day ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
1 day ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
3 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
3 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago