Sorting using Pointers

This is a discussion on Sorting using Pointers within the C Programming forums, part of the General Programming Boards category; Hi guys, How would you sort an array using pointers BUT not change the original array or create any other ...

  1. #1
    aspand
    Guest

    Question Sorting using Pointers

    Hi guys,
    How would you sort an array using pointers BUT not change the original array or create any other integer arrays.
    Please do let me know. Thanks
    A

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Create an array of pointers to whatever type your array is. Make them point to each individual cell, and sort the list of pointers.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    63
    Hi Quzah..
    what would some of the code look like. As in how would I do the pointing (if you know what I mean)? I know thats the right idea. I am just having a lil difficulty w/ the code. Thanks
    A

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by aspand
    Hi Quzah..
    what would some of the code look like. As in how would I do the pointing (if you know what I mean)? I know thats the right idea. I am just having a lil difficulty w/ the code. Thanks
    A
    <sometype> array[SOME_SIZE];
    <sometype> *somearray[SOME_SIZE];

    somearray[x] = &array[y];

    Basicly all you do is change the address that a given cell in 'somearray' points to, and sort it that way. The original array will remain untouched.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Variable pointers and function pointers
    By Luciferek in forum C++ Programming
    Replies: 11
    Last Post: 08-02-2008, 02:04 AM
  3. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  4. moving pointers to pointers
    By Benzakhar in forum C++ Programming
    Replies: 9
    Last Post: 12-27-2003, 07:30 AM
  5. sorting with pointers
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 03-17-2002, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21