My first post! Congratulations
BFP = Big F**king Problem
First...I'm sorry if my English is wrong!(I'm from Bulgaria)
Second: Please don't delete my Post! I've read at least 20 sites with google search and in a lot of forums to understand and repair my problem! So just please help.
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.
I'm trying to sort a doubly-linked list without any success for 3 days! Please help me, I know, that you can.
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:
struct worker a;
struct element *next;
struct element *previous;
typedef struct element element;
element *head, *tail;
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.
I must sort that dates:
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:
void createElement(struct worker a)
if (head == NULL)
newElement=(struct element *)malloc (sizeof(struct element));
newElement->a=a; //tuk vlizat proverenite danni i ukazatelq gi izvlicha
newElement->previous = NULL;
newElement = (struct element *)malloc (sizeof(struct element));
tail = newElement;
and the dates of elements (workers) are like the example before...in that row.
I tried lot of ways, but nothing work!!!
like that for example:
/* else if(strcmp(findElement->a.date, findElement->next->a.date)<0)
else if(strcmp(head->a.date, findElement->next->a.date)<=0)
else if(strcmp(find->a.date, find->next->a.date)>=0)
or other ways, that I haven't yet, but they don't work.
THANKS A LOT!