Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.
Answer Posted / manesh nambiar
int return_fifth_from_end()
{
int i,j;
struct node *p,*q;
*p=HEAD_NODE;
for(i=0;i<4;i++)//will make p point to the 5th element
{
p=p->next;
if(p==NULL)
{
printf("List has less than 5 elements");
}
}
q=HEAD_NODE;
while(p!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}
Is This Answer Correct ? | 8 Yes | 7 No |
Post New Answer View All Answers
Why is c called a structured programming language?
How can I change their mode to binary?
What is getch() function?
Why is it usually a bad idea to use gets()? Suggest a workaround.
In a switch statement, explain what will happen if a break statement is omitted?
On most computers additional memory that is accessed through an adapter of feature card along with a device driver program. a) user memory b) conventional memory c) expandedmemory d) area
Can we declare function inside main?
write a program to print the consecutive repeated character from the given string... input string is : hhhhjkutskkkkkggggj output should be like this: hhhhkkkkkgggg anyone help me...
Multiply an Integer Number by 2 Without Using Multiplication Operator
What is realloc in c?
c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above
What language is lisp written in?
What are the restrictions of a modulus operator?
Why do we use stdio h and conio h?
Differentiate between calloc and malloc.