Telegram Group & Telegram Channel
134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy



tg-me.com/C_Codings/195
Create:
Last Update:

134. Program to delete a node for a given element from linked list.

#include <stdio.h>
#include<stdlib.h>

typedef struct node {
int data;
struct node *next;
}Node;

int main(void)
{
Node*temp;
Node*start=NULL;
Node* p=NULL;

int n;
scanf("%d",&n);

while(n--)
{
temp=(Node *)malloc(sizeof(struct node));
scanf("%d",&temp->data);
temp->next=NULL;

if(start==NULL)
{
start=temp;
p=temp;
}
else
{
p->next=temp;
p=temp;
}
}

printf("Element to delete : ");
int ele; scanf("%d",&ele); printf("%d\n",ele);
Node*prev=start;
Node*cur=start;

while(cur!=NULL)
{
if(start->data==ele)
{
start=start->next;
}

if(cur->data==ele)
{
prev->next=cur->next;
free(cur);
break;
}
prev=cur;
cur=cur->next;

if(cur==NULL)
{
printf("Element doesn't exist!");
exit(0);
}
}

while(start!=NULL)
{
if(start->next!=NULL)
printf("%d->",start->data);
else
printf("%d",start->data);

start=start->next;
}

return 0;
}
#program_by : @freakyLuffy

BY C Language πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/C_Codings/195

View MORE
Open in Telegram


C Language ‍ Telegram | DID YOU KNOW?

Date: |

China’s stock markets are some of the largest in the world, with total market capitalization reaching RMB 79 trillion (US$12.2 trillion) in 2020. China’s stock markets are seen as a crucial tool for driving economic growth, in particular for financing the country’s rapidly growing high-tech sectors.Although traditionally closed off to overseas investors, China’s financial markets have gradually been loosening restrictions over the past couple of decades. At the same time, reforms have sought to make it easier for Chinese companies to list on onshore stock exchanges, and new programs have been launched in attempts to lure some of China’s most coveted overseas-listed companies back to the country.

Telegram Gives Up On Crypto Blockchain Project

Durov said on his Telegram channel today that the two and a half year blockchain and crypto project has been put to sleep. Ironically, after leaving Russia because the government wanted his encryption keys to his social media firm, Durov’s cryptocurrency idea lost steam because of a U.S. court. β€œThe technology we created allowed for an open, free, decentralized exchange of value and ideas. TON had the potential to revolutionize how people store and transfer funds and information,” he wrote on his channel. β€œUnfortunately, a U.S. court stopped TON from happening.”

C Language ‍ from us


Telegram C Language πŸ‘¨β€πŸ’»
FROM USA