Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.
Answer Posted / gbohrn
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->next!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}
| Is This Answer Correct ? | 5 Yes | 6 No |
Post New Answer View All Answers
What the advantages of using Unions?
Explain what is the benefit of using an enum rather than a #define constant?
What would happen to X in this expression: X += 15; (assuming the value of X is 5)
Describe the order of precedence with regards to operators in C.
Explain how can I right-justify a string?
What is the concatenation operator?
What is omp_num_threads?
What is a good way to implement complex numbers in c?
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f
What is the use of bitwise operator?
Is c procedural or object oriented?
What is the value of c?
Explain how can you tell whether two strings are the same?
What should malloc(0) do?
what is the function of pragma directive in c?