My first post! Congratulations
BFP = Big F**king Problem

First...I'm sorry if my English is wrong!(I'm from Bulgaria)
Third: Before one week, I know only few about Programming in C, some arrays, basic things, the loops, but my source is over 1200 lines, so help me to finish it, please.

So...
The idea is to sort the first two elements, than to compare the next two and something like that...Yet I'm very very CONFUSED.

this is my struct for an element of the doubly-linked list:

Code: C
struct element
{
struct worker a;
struct element *next;
struct element *previous;
};
typedef struct element element;
In struct worker, I must sort the workers in a firm by the length of service (in increasing) in that firm, I know the date of the appoin for every worker I added in the list.
For Example:
I must sort that dates:
11.11.2003
11.12.2003
11.11.2006
11.11.2004
11.11.2005
11.11.2007
like that: 11.11.2007>11.11.2006>11.11.2005>11.11.2004>11.12> 2003>11.11.2003
Important: We don't know the number of the workers, and when we sort the list, we can add more workers, and than we must sort with the new again for example.

in that code, I add workers to the list:
Code: C
void createElement(struct worker a)
{
element *newElement;

{
newElement=(struct element *)malloc (sizeof(struct element));
newElement->a=a; //tuk vlizat proverenite danni i ukazatelq gi izvlicha
newElement->previous = NULL;
}
else
{
newElement = (struct element *)malloc (sizeof(struct element));
newElement->a=a;
tail->next=newElement;
newElement->previous=tail;
}
tail = newElement;
newElement->next=NULL;
}

and the dates of elements (workers) are like the example before...in that row.

FOR SORT:
I tried lot of ways, but nothing work!!!

like that for example:

Code: C
void sortWorkers()
{
element *findElement;
int f=1;

while(findElement!=NULL)
{
while(f!=0)
{
{
findElement=findElement->next;
f=0;
}
/*    else if(strcmp(findElement->a.date, findElement->next->a.date)<0)
{
findElement=findElement->next;
f=0;
} */

{
f=0;
}
}findElement=findElement->next;
f=1;
}
}

or:
Code: C
void sortWorkers()
{
element *find;
element *temp;

do
{
if(strcmp(find->a.date, find->next->a.date)<0)
{
temp=find->next->previous;
temp->next->next->previous=find->next->previous;
temp->next=find->next->previous;
temp->next->previous=find->previous;
temp->next->next=find->next->next;
find=temp;
}
else if(strcmp(find->a.date, find->next->a.date)>=0)
{
find=find->next;
}
}while(find->next!=NULL);
}

or other ways, that I haven't yet, but they don't work.

THANKS A LOT!

Last edited by shabbir; 1Sep2007 at 07:02.. Reason: Code block