Exploring My Technical Learnings... Which could be a doubt or solution..!
Thursday, October 21, 2010
Few tricky code snaps on Linked List....
Few months back, when i was started for attending interviews to get into so called software industry, my thoughtprocess was not in line. Also because of language and other non-technical issues, every question was new and challenging to answer...!
At that point of time, i have decided to get benefited from all the interviews i attend. Thats how my notes called 'Notes from Interviews, Notes for Interviews' got its birth. At that point of time, i didn't have my technical blog.
So, now i am putting some of those into my blog to get remembered and to make you all remembered...!
Data structures(stack, queues ans Linked Lists) was one of my interesting subjects. Also because of this subject only i learned something about C language. Before that, i didn't know about what printf will do, what is getch() etc. One day before of my lab exam in 1st sem, i had written each lab program 150 times to get passed in exam.....!!!!!
Other interesting thing is, to understand DS better, i have taken DS exam twise....!!!(?) (understood)
Here, i am sharing some tricky questions on Singly linked list.
Deletion of a node whose address only known in a singly linked list.
Node_Deletion(NODE ptr)
{
NODE next;
ptr->data = ptr->link->data;
next = ptr->link;
ptr->link = ptr->link->link;
free(next);
}
Reversing a singly linked list:
void Revrse_SSL(NODE first)
{
NODE ptr, pre=0, next;
ptr = first;
next = ptr->link;
while(ptr->link)
{
ptr->link = pre;
pre = ptr;
ptr = next;
next=next->link;
}
ptr->link = pre;
}
Finding out a middle node of a singly linked list;
FindMiddleNode(NODE first)
{
NODE current, mid;
int check = 0;
current=mid=first;
while(current)
{
current = current->link;
check = (check+1)%2;
if(check==0)
mid = mid->link;
}
return mid->info;
}
There could be some other ways to do same as above. If you would like to share, drop me a mail the same.
Always welcome to comments and suggestions...
Have a great career...
------
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment