NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//Write a program to implement link list
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node{
int info;
struct node *next;
}nodetype;
nodetype *head;
//head=NULL
void insert_atfirst(int);
void insert_givenposition(int);
void insert_atend(int);
void del_first();
void del_last();
void del_nthnode();
void info_sum();
void count_nodes();
void main(){
int choice,item;
do{
printf("nnn-------------Menu for Linked List Program-------------n");
printf("n1.Insert first n2. Insert at given position n3. Insert at last n4. del first node");
printf("n5. del the last node n6. del the nth node n7. Display items n8. Count nodes n9. exitn");
printf("nEnter the choice:");
scanf("%d",&choice);
switch(choice){
case 1:
printf("Enter the item to be inserted:");
scanf("%d",&item);
insert_atfirst(item);
break;
case 2:
printf("Enter the 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:
del_first();
break;
case 5:
del_last();
break;
case 6:
del_nthnode();
break;
case 7:
info_sum();
break;
case 8:
count_nodes();
break;
case 9:
exit(0);
default:
printf("nnINVALID DATA ENTRYn");
}
}while(choice!=9);
}
//function definition
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 del_first(){
nodetype *temp;
if(head==NULL){
printf("Void deletionn");
}
else{
temp=head;
head=head->next;
free(temp);
}
}
void del_last(){
nodetype *hold,*temp;
if(head==NULL){
printf("Void deletionn");
}
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 del_nthnode(){
nodetype *hold,*temp;
int pos,i;
if(head==NULL){
printf("Void deletionn");
}
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.