Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1021259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:17:05+00:00 2026-05-16T11:17:05+00:00

I have been trying to implement XOR linked list and its operations but I

  • 0

I have been trying to implement XOR linked list and its operations but I have not been able to do it properly.

Is it possible to implement it in C since XOR link list involves operations on addresses?

I would be very thankful if some actual working code is given.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:17:05+00:00Added an answer on May 16, 2026 at 11:17 am

    That’s an interesting idea that I have not seen before. With today’s fairly abundant memory, it seems like a lot of complexity for little gain (although not all platforms are flush with memory). Edit While doing my real work, my mind kept drifting back to it, so I added the function to create the new node and put it on the given end. Prettier now. It’s rather cool that both the addnode and traverse functions are symmetrical. Neither needs to know the direction. Just give it one end of the list and they operate correctly.

    And based on Darron’s comment (thanks), I changed the int to intptr_t for portability.

    #include <stdio.h>
    #include <malloc.h>
    #include <stdint.h>  // gcc needs this for intptr_t.  
    
    typedef struct xorll {
       int  value;
       struct xorll  *np;
    }  xorll;
    
    
    // traverse the list given either the head or the tail
    void traverse( xorll *start )  // point to head or tail
    {
       xorll *prev, *cur;
    
       cur = prev = start;
       while ( cur )
          {
          printf( "value = %d\n", cur->value );
          if ( cur->np == cur )
             // done
             break;
          if ( cur == prev )
             cur = cur->np;   // start of list
          else {
             xorll *save = cur;
             cur = (xorll*)((uintptr_t)prev ^ (uintptr_t)cur->np);
             prev = save;
             }
          }
    }
    
    // create a new node adding it to the given end and return it
    xorll* newnode( xorll *prev, xorll *cur, int value )
    {
       xorll *next;
    
       next = (xorll*)malloc( sizeof( xorll ));
       next->value = value;
       next->np = cur;  // end node points to previous one
    
       if ( cur == NULL )
          ; // very first node - we'll just return it
       else if ( prev == NULL ) {
          // this is the second node (they point at each other)
          cur->np = next;
          next->np = cur;
          }
       else {
          // do the xor magic
          cur->np = (xorll*)((uintptr_t)prev ^ (uintptr_t)next);
          }
    
       return next;
    }
    
    
    
    int main( int argc, char* argv[] )
    {
       xorll *head, *tail;
       int   value = 1;
    
       // the first two nodes point at each other.  Weird param calls to
       // get the list started
       head = tail = newnode( NULL, NULL, value++ );
       tail = newnode( NULL, tail, value++ );
    
       // now add a couple to the end
       tail = newnode( tail->np, tail, value++ );
       tail = newnode( tail->np, tail, value++ );
    
       // this is cool - add a new head node
       head = newnode( head->np, head, 999 );
    
    
       printf( "Forwards:\n" );
       traverse( head );
       printf( "Backwards:\n" );
       traverse( tail );
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to implement my own linked list class for didactic purposes.
I have been trying to implement a GlassPane for my games' in-game HUD, but
Hello guys, I have been trying to implement the DSUM function but failed to
I have been trying to implement a small SERVER - CLIENT app but ran
I have been trying to implement the delete BST function but I don't know
I have been trying to implement a comment engine in my app (UItableView) but
I have been trying to implement an upgrade plan for my Android app which
I have been trying for the past two days now to implement Admob ads
I have been having this annoying problem when trying to implement a picture gallery
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.