displaying data in linked list

How would I display this linked list in order from least to greatest, with this function?

1
2
3
4
5
6
7
  node *temp = list;
      while (temp != NULL) {
      cout << "[" << temp ->data << "] ";
      temp = temp ->next;
    }
    cout << endl;
  }
For that you'd have to sort the list first. Assuming yours is a single linked list, google 'sorting singly linked list' and see which approach best suits your needs
Topic archived. No new replies allowed.