473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pls guide me to write a program in c sort a linked list using selection sort

pls help me to write a program in c that reads n elements of type float, stores them in a linked list ,sort it in the descending order using selection sort methods, and finally output the sorted linear linked list
Sep 5 '06 #1
4 5855
Banfa
9,065 Expert Mod 8TB
You write it and we'll help you debug it.
Sep 5 '06 #2
Just write the code using following steps:

1. Start two loops.
2. In the outer loop access all the nodes except the last node.
3. in the inner loop access all nodes the nodes from the node following the node pointed by the variable in the outer loop
4. then check the values and accordingly swap the nodes.
5. go to the next node in the inner loop
6. go to the next node in the outer loop
Sep 6 '06 #3
Just write the code using following steps:

1. Start two loops.
2. In the outer loop access all the nodes except the last node.
3. in the inner loop access all nodes the nodes from the node following the node pointed by the variable in the outer loop
4. then check the values and accordingly swap the nodes.
5. go to the next node in the inner loop
6. go to the next node in the outer loop

To add to this one more hint.,

PREVIOUS_NODE;
TEMP_NODE; //
TEMP_NODE->PTR = NEXT_NODE->PTR;
if(CURRENT_NODE->VALUE < NEXT_NODE->VALUE)
{
NEXT_NODE->PTR = PREVIOUS_NODE->PTR;
PREVIOUS_NODE->PTR = CURRENT_NODE->PTR;
CURRENT_NODE->PTR = TEMP_NODE->PTR ;
}




ALL the 4 TEMP_NODE,PREVIOUS_NODE,CURRENT_NODE,NEXT_NODE belong to the same linked list and the rest is just traversal and looping.
Sep 7 '06 #4
duaa
1
i need shell,selection,inseration,bubble sorting in linked list please
Nov 27 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
3
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h>...
6
by: Julia | last post by:
I am trying to sort a linked list using insertion sort. I have seen a lot of ways to get around this problem but no time-efficient and space-efficient solution. This is what I have so far: ...
0
by: Svenn Bjerkem | last post by:
Hi, Armed with Programming Python 3rd Edition and Learning Python 2nd edition I try to write an application which I at first thought was simple, at least until I was finished with the GUI and...
2
by: pchahar | last post by:
Write a program to process a text file. The program will determine how many unique words there are in the text file that begin with each letter of the alphabet. The text file name will be given as a...
6
by: Nick Valeontis | last post by:
I know how to use Icomparable. However, I can't figure out how to sort a generic linked list? (without writing the algorithm) Lets say I have something like this: class...
1
by: Homeworkboy | last post by:
Can anyone help me with this program? Look at the bottom of this program for help methods: /*1. Make a program that uses numbers from 1 to 100 including each ends which puts the even...
4
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.