placement Paper

Answer Posted / printf

# 1
/*OPERATIONS ON SINGLY LINKED LIST*/

#include<stdio.h>
#include<conio.h>
struct link
{
int item;
struct link *next;
};
typedef struct link node;
void addfirst();
void addlast();
void addmid();
void delfirst();
void dellast();
void delmid();
void display();
node *head=NULL;


void main()
{
int ch;
clrscr();
do
{
printf("\nSINGLY LINKED LIST OPERATIONS\n");
printf("\n1.Addfirst\n2.AddMid\n3.AddLast\n4.DeleteFirst\n5.DeleteMiddle\n6.DeleteLast\n7.Display\n8.Exit\n");
printf("Enter your option:\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
addfirst();
display();
break;
case 2:
addmid();
display();
break;
case 3:
addlast();
display();
break;
case 4:
delfirst();
display();
break;
case 5:
delmid();
display();
break;
case 6:
dellast();
display();
break;


case 7:
display();
break;
case 8:
exit(0);
break;
default:
printf("Invalid Choice\n");
}
}
while(ch<=8);
getch();
}


void addfirst()
{
node *temp;
temp=(node *)malloc(sizeof(node));
printf("Enter the data....\t");
scanf("%d",&temp->item);
temp->next=head;
head=temp;
}

void addmid()
{
int i=1,pos;
node *cur=head,*temp;
printf("\nEnter the position\t");
scanf("%d",&pos);
while(pos!=i+1&&cur!=NULL)
{
cur=cur->next;
i++;
}
if(pos==i+1)
{
temp=(node *)malloc(sizeof(node));
printf("Enter the data...");
scanf("%d",&temp->item);
temp->next=cur->next;
cur->next=temp;
}
}


void addlast()
{
node *temp,*cur=head;
temp=(node *)malloc(sizeof(node));
printf("\nEnter the data....");
scanf("%d",&temp->item);
while(cur->next!=NULL)
{
cur=cur->next;
}
temp->next=cur->next;
cur->next=temp;
}


void delfirst()
{
node *temp=head;
head=head->next;
printf("Deleted item is %d\n",temp->item);
free(temp);
}


void delmid()
{
int i=1,pos;
node *cur=head,*temp;
printf("Enter the position to be deleted\t");
scanf("%d",&pos);
while(pos!=i+1&&cur->next!=NULL)
{
cur=cur->next;
i++;
}
if(pos==i+1)
{
temp=cur->next;
cur->next=temp->next;
printf("Deleted item is %d\n",temp->item);
free(temp);
}
}


void dellast()
{
node *temp,*cur=head;
while(cur->next->next!=NULL)
{
cur=cur->next;
}
temp=cur->next;
cur->next=NULL;
printf("Deleted item is %d\n",temp->item);
free(temp);
}


void display()
{
node *cur=head;
printf("\nHead->");
while(cur!=NULL)
{
printf("\t%d",cur->item);
cur=cur->next;
}
printf("<-NULL\n");
}

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

speak 1min on topic Travelling,memorable moment ,memorable day?

1738


Danlaw placement questions and answers

1352


my question is : reverse a string in COBOL program (please write a code asap) input file: 1234abcdef output file: 8765_____ abc*$#1___ 1_2_3_4__ cdef____ghi h_k_z_a__ a_z_k_h___ ihg____ghi 4_3_2_1___ 1#$*cba__ ______5678 fedcb4321

1293


what you will do when you struck in traffic ?

1049


printf("%d",printf("%d",printf("%d",printf("%s","ILOVECPROGRAM")))); whats the output

1394






HI SIR I WANT PREVIOUS QUESTION PAPER OF HPCL I M CHEMICAL ENGG.

1945


What kind of Issues/bugs arise in ETL projects? I would like to know few issues (critical to somewhat bugs ) normally occur in ETL process especially when testing? Domains can be banking, retail or any.

1424


your project to describe and tell about : 1. My favorite things 2. My favorite places at home 3. Animals *Choose one of them to describe *Write on your paper *If you done, Send me *Did you get it

784


What were the occupations of the people who lived within the Mauryan Empire?

579


email me previous question papers of bob bank for po exams

2060


my question is : reverse a string in COBOL program (please write a code asap) input file: 1234abcdef abc*$#1___ cdef____ghi a_z_k_h___ 4_3_2_1___ ______5678 output file: 8765_____ 1_2_3_4__ h_k_z_a__ ihg____ghi 1#$*cba__ fedcb4321

1192


how did you celebrate your last birthday?

1275


Do we have vacancy for HR RECRUITER ?

1376


aptitude

697


what is placement paper?

2149