write a C code To reverse a linked list

Answer Posted / sujith

include <stdio.h>

typedef struct list {
list_t *next;
int data;

}list_t;
list_t *list_reverse(list_t *list)
{
list_t *rlist = NULL;
while (list != NULL)
{
list_t *next = list->next;
list->next = rlist;
rlist = list;
list = next;
}
return rlist;
}
This will do the job.
Plese do verify this.
Sujith

Is This Answer Correct ?    27 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the use of #pragma exit?

711


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3739


How do I round numbers?

608


What is difference between array and pointer in c?

546


What is the difference between array and structure in c?

577






What is the difference between new and malloc functions?

587


Can you define which header file to include at compile time?

601


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

4849


Do character constants represent numerical values?

852


What's a good way to check for "close enough" floating-point equality?

636


Explain how can I open a file so that other programs can update it at the same time?

603


What is the use of parallelize in spark?

582


What oops means?

594


can we implement multi-threads in c.

679


Why cant I open a file by its explicit path?

602