GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Apr-2008, 07:08
moody moody is offline
New Member
 
Join Date: Mar 2008
Posts: 22
moody has a little shameless behaviour in the past

Need help with linked lists


Hello!


I'm a having some trouble doing a list of linked lists of countries exercise,each of which have survey replies.The exercise says:

"Write a function in c that detects when a country does not follow alphabetical order.The function must find that country(assume there's only one district!) and place it on the correct location on the list.All the information regarding the survey must be preserved.The function takes as an argument a pointer to the beggining of the list of countries(main list) and returns that same pointer updated"

What I have trouble is, how will I run through the linked list?Do I have to use some kind of algorithm like bubble sort?Or is there any simpler way?And if I use bubble sort,how do I make a stopping condition once the district that wasn't in place gets ialphabetically ordered?
Here's what I have right now,but what it does is,that only considers the element tha follows the 1st element to be alphabetically lower than it(Ex: Belgium->Australia->New Zeland -> Australia->Belgium->New Zeland)
Here's the code:

CPP / C++ / C Code:
dpno update(dpno list)
{
	dpno aux,ant;

	if(list!=NULL)
	{
	
		ant=list;
		aux=ant->prox;
		if(strcmp(aux->name,list->name)<0)
		{
			ant->prox=aux->prox;
			aux->prox=ant;
			ant=aux;
			list=ant;
			return list;
		}

         }
        return list;
}
  #2  
Old 06-May-2008, 17:27
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 425
Peter_APIIT is on a distinguished road

Re: Need help with linked lists


Quote:
What I have trouble is, how will I run through the linked list?Do I have to use some kind of algorithm like bubble sort

You just need iterate from head of list until tail of list.

You should use insertion sort.
__________________
Linux is the best OS in the world.
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Lists Database... TS3BxL C++ Forum 10 19-Mar-2008 22:37
Linked Lists problem kracivi C Programming Language 1 01-May-2007 08:40
Doubly linked lists in C++ sweeeeeeetlipss C++ Forum 1 23-Oct-2006 23:27
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Linked lists vortz83 C++ Forum 3 20-Mar-2004 06:56

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:38.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.