NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include<stdio.h>
#include<conio.h>
#include<malloc.h> //for malloc function
#include<process.h> //fpr exit function
struct node
{
int info;
struct node *next;
};

typedef struct node NodeType;
NodeType *head;
//head=NULL;
void insert_atfirst(int);
void insert_givenposition(int);
void insert_atend(int);
void delet_first();
void delet_last();
void delet_nthnode();
void info_sum();
void count_nodes();
int main()
{
int choice;
int item;
//clrscr();
do
{
printf("nnnn------------------- Manu for Linked List Program:---------------------n");
printf("1. insert first n2.insert at given position n3 insert at last n4:Delete first node n5:delete last node n6:delete nth node n7:Display items n8count nodes n9:exitn");
printf("enter your choicen");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter item to be inserted");
scanf("%d",&item);
insert_atfirst(item);
break;

case 2:
printf("Enter item to be inserted");
scanf("%d",&item);
insert_givenposition(item);
break;

case 3:
printf("Enter item to be inserted");
scanf("%d",&item);
insert_atend(item);
break;

case 4:
delet_first();
break;
case 5:
delet_last();
break;

case 6:
delet_nthnode();
break;

case 7:
info_sum();
break;

case 8:
count_nodes();
break;

case 9:
exit(1);
break;

default:
printf("invalid choicen");
break;
}
}while(choice<10);
getch();
}

/************function definitions**************/
void insert_atfirst(int item)
{
NodeType *nnode;
nnode=(NodeType*)malloc(sizeof(NodeType));
nnode->info=item;
nnode->next=head;
head=nnode;
}

void insert_givenposition(int item)
{
NodeType *nnode;
NodeType *temp;
temp=head;
int p,i;
nnode=( NodeType *)malloc(sizeof(NodeType));
nnode->info=item;
if (head==NULL)
{
nnode->next=NULL;
head=nnode;
}
else
{
printf("Enter Position of a node at which you want to insert an new noden");
scanf("%d",&p);
for(i=1;i<p-1;i++)
{
temp=temp->next;
}
nnode->next=temp->next;
temp->next=nnode;
}
}

void insert_atend(int item)
{
NodeType *nnode;
NodeType *temp;
temp=head;
nnode=( NodeType *)malloc(sizeof(NodeType));
nnode->info=item;
if(head==NULL)
{
nnode->next=NULL;
head=nnode;
}
else
{
while(temp->next!=NULL)
{
temp=temp->next;
}
nnode->next=NULL;
temp->next=nnode;
}
}

void delet_first()
{
NodeType *temp;
if(head==NULL)
{
printf("Void deletion|n");
return;
}
else
{
temp=head;
head=head->next;
free(temp);
}
}

void delet_last()
{
NodeType *hold,*temp;
if(head==NULL)
{
printf("Void deletion|n");
return;
}
else if(head->next==NULL)
{
hold=head;
head=NULL;
free(hold);
}
else
{
temp=head;
while(temp->next->next!=NULL)
{
temp=temp->next;
}
hold=temp->next;
temp->next=NULL;
free(hold);
}
}
void delet_nthnode()
{
NodeType *hold,*temp;
int pos, i;
if(head==NULL)
{
printf("Void deletion|n");
return;
}
else
{
temp=head;
printf("Enter position of node which node is to be deletedn");
scanf("%d",&pos);
for(i=1;i<pos-1;i++)
{
temp=temp->next;
}
hold=temp->next;
temp->next=hold->next;
free(hold);
}
}

void info_sum()
{
NodeType *temp;
temp=head;
while(temp!=NULL)
{
printf("%dt",temp->info);
temp=temp->next;
}
}

void count_nodes()
{
int cnt=0;
NodeType *temp;
temp=head;
while(temp!=NULL)
{
cnt++;
temp=temp->next;
}
printf("total nodes=%d",cnt);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.