Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Sorting Linked Lists

Sorting Linked Lists

Scheduled Pinned Locked Moved Managed C++/CLI
algorithmsdata-structuresdatabasequestiondiscussion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    budidharma
    wrote on last edited by
    #1

    Hi! I'm learning about linked lists and have created the following class: struct Node { int data; Node *next; Node *prev; }; class BasicList { public: /* CONSTRUCTORS / DESTRUCTORS */ BasicList(); // Default Constructor /* INSERTION METHODS */ void Prepend(int n); // Insert n into list as the first item void Append(int n); // Insert n into list as the last item void InsertAfter(int key, int n); // Insert n into list after key void InsertBefore(int key, int n); // Insert n into list before key void Swap(int first, int second); // Swap specified elements void Remove(int key); // Remove first occurance of key from list /* QUERY METHODS */ void DisplayNodes() const; // Display the data item from each node in the list bool IsEmpty() const; // Return true if the list is empty int Maximum() const; // Return the largest member in the list int Minimum() const; // Return the smallest member in the list int Occurances(int key) const; // Return the number of occurances of key int NumNodes() const; // Return the number of nodes in the list /* HELPER FUNCTIONS */ Node *GetAddress(int n); // Returns the address of the first instance of n found in list int *GetDataArray(); // Return a pointer to an array containing the data. Last item in array is NULL private: /* MEMBERS */ Node *head; // pointer to empty head node Node *tail; // pointer to empty tail node }; All the functions work wonderfully so far. I want to add a method that will sort the linked list data. I'm not really sure where to begin. I checked Wikipedia, and found the following URL which presents a MergeSort algorithm. I'm not sure if this is the best way. Any opinions? http://en.wikipedia.org/wiki/Merge\_sort

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups