Hi there,

I made a linked list program to add, delete, add in the middle and delete from anywhere.
I'm searching to make a function to sort the string data that I have in lexicographic order.

Here's my struct:

struct node
{
    char data[100];
    struct node *previous;  // Points to the previous node
    struct node *next;   // Points out to the next node
}*head, *last;

Any help?

Okay so i have an example here that I found on your very useful link.
I'm just stuck on what to do on the: struct jsw_node result = {0};
what do i need to change this for?

 1 void jsw_insertion ( struct jsw_list *list )
 2 {
 3   struct jsw_node result = {0};
 4   struct jsw_node *i, *step, *next;
 5 
 6   for ( step = list->head; step != NULL; step = next ) {
 7     next = step->next;
 8 
 9     for ( i = &result; i->next != NULL; i = i->next ) {
10       if ( i->next->data > step->data )
11         break;
12     }
13 
14     step->next = i->next;
15     i->next = step;
16   }
17 
18   list->head = result.next;
19 }

can you post a code as an axample?
I'm not sure of how to do it.

I'm a newbie in C sorry i'm asking a lot

if( strcmp(  i->next->data, step->data ) > 0)
{


}

I'm a newbie in C sorry i'm asking a lot

Not a problem -- we were all in your shoes at one time or another.

Edited 2 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.