Are looking for specific interview question?!
There are so many simple ways of reversing a link list!! A simple systematic approach is to have these functions:
1. insert_head(List, element) returns new list by inserting element before head.
2. delete_head(List) returns head element after deleting from the list.
Assume the type this way:
typedef struct List_s {
struct List_s *next;
} List;
Then insert_head can be defined as:
List*
insert_head(List *l, List *e)
{
e->next = l;
return e;
}
delete_head would be:
List* delete_head(List **l)
{
List *e;
if (!l || !*l) return NULL;
e = *l;
*l = e->next;
return e;
}
Reverse would be a simple while loop:
List*
reverse_list(List *h)
{
List *n = NULL;
while (h) {
n = insert_head(n, delete_head(h));
}
return n;
}
Tuesday, January 2, 2007
Subscribe to:
Post Comments (Atom)
Thats mee ...
About Me
- Naresh Kumar
- Delhi, Delhi, India
- I am an Electrical Engineering student of Indian Institute of Technology, Delhi. I am currently in 5th year of my Dual Degree course. By the end of this course I will proudly be called Masters in Information and Communication Technology. I have hard core programming interest and good at Networking Fundamentals. Enjoy surfing around Linux journals.
Blog Archive
-
▼
2007
(13)
-
▼
January
(12)
- IP Masquerading with Linux
- Developing P2P Protocols across NAT
- A Stream Socket API for C++
- Sockets API
- Ch-1 Networking Basics
- Ch-1 Networking Basics
- Network Programming
- IBM tech paper for placement .. I only hope that i...
- For Network Managers
- Anothr good Problem
- check with tis.... NODE reverse(NODE first){NODE ...
- Are looking for specific interview question?! The...
-
▼
January
(12)
1 comment:
Great work .. We can hardly find good guys like you . Nice work man .. really helped me a lot .. It seems that you are a really intelligent guy.
All the best
Post a Comment