interview questions and answers

Technical Interview Questions | DataStructure Interview Questions

Home interview questions Programming interview questions DataStructure 
Saturday, 11 February 2012
Main Menu
Home
Online Test
Contest
Search
FAQs
Contact Us
Login
Most Popular Category
JAVA

Microsoft Technologies
ASP, C#, DotNet, ...

Programming
C++, PHP, VB, ...

SAP

Testing

Web Technologies

Polls
Does personal networking help in job search?
 
IT Placement Papers interview questions Programming interview questions DataStructure

This category contains DataStructure Interview Questions and Answers


Sort a linked list

PDF Print E-mail


//sorting in descending order
struct node
{
int value;
node* NEXT;
}
//Assume HEAD pointer denotes the first element in the //linked list
// only change the values…don’t have to change the //pointers

Sort( Node *Head)
{
     node* first,second,temp;
    first= Head;
    while(first!=null)
    {
        second=first->NEXT;
        while(second!=null)
            {
                if(first->value < second->value)
                {
                    temp = new node();
                    temp->value=first->value;
                    first->value=second->value;
                    second->value=temp->value;
                    delete temp;
                }
           second=second->NEXT;
        }

        first=first->NEXT;
   }
}

 


Be first to comment this article

Only registered users can write comments.
Please login or register.

 
< Prev   Next >

Technical Interview Questions | DataStructure Interview Questions

Top!
Top!
Copyright © 2008 InterviewDuniya.com All Rights Reserved.
Partner Site: Maheshwari Matrimony