Problem #6 XOR Linked List

2020. 8. 15. 20:37PS/도전

All problems are from https://www.dailycodingproblem.com/

 

Solution Codes : https://github.com/Kusin/DailyCoding

Daily Coding Problem #6 XOR Linked List

An interesting Problem

 

Let's Implement this with C++

 

1. Note XOR Operations

  • X⊕X = 0
  • X⊕0 = X
  • X⊕Y = Y⊕X
  • (X⊕Y)⊕Z = X⊕(Y⊕Z)

What we have to decoy is the following equation:

A⊕(A⊕C) = (A⊕A)⊕C = 0⊕C = C

 

 

Now we can Traverse the Linked List if we save the address of first Element of XLL (XOR Linked List)

its value is the address of next element.

 

How to XOR pointers in C++/C

 

https://stackoverflow.com/questions/26569728/using-xor-with-pointers-in-c

 

Using XOR with pointers in C

Last week, our teacher gave us an assignment to make a double linked list in C without using two pointers in the struct; we have to implement it just using one pointer to point to the next and prev...

stackoverflow.com

 

Implementation

728x90

'PS > 도전' 카테고리의 다른 글

Problem#8 :Unival Subtrees  (0) 2020.08.16
Problem#7 : Decoding Possibility  (0) 2020.08.15
Problem #5 Implementing Pair in Python  (0) 2020.08.15
Problem #4 : First missing positive integer  (0) 2020.08.15
#3 Parse & ReverseParse a Binary Tree  (0) 2020.08.15