CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    1

    singly linked list swap pairs... I've hit a brick wall

    Thanks.
    Last edited by Moooni; August 19th, 2008 at 06:43 AM.

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: singly linked list swap pairs... I've hit a brick wall

    The algorithm is :

    Code:
    If N is node to swap and N->Next is next in list then to swap N and N->Next
    
    If N is end of list (i.e. N->Next == null) Then Error
    
    If N is Head of list then
       Head of list = N->Next
       N->Next  = Head of list->Next
       Head of list->Next = N
    Else
       Find Previous node to N.
       Previous node To N->Next = N->Next
       N->Next = Previous node to N->Next
       Previous Node to N->Next = N
    Darwen.
    Last edited by darwen; August 16th, 2008 at 07:29 AM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured