| | |
xor linked list
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
class xll
{
public:
int data;
unsigned long link;
};
class xlist
{
xll *head,*tail;
xlist(){head = NULL;tail = NULL}
void insert(int);
};
void xlist :: insert (int ele)
{
xll *node = (xll*) malloc (sizeof(xll));
node->data = ele;
xll *temp = head,*prev = NULL;
while(temp != NULL)
{
next = (xll *) (temp->link ^ (unsigned long) prev);
prev = temp;
temp = next;
}
if(prev == NULL)
head = node;
else
{
node->link ^= (unsigned long) prev ^ (unsigned long) temp;
prev->link ^= (unsigned long) temp ^ (unsigned long) node;
temp->link ^= (unsigned long) prev ^ (unsigned long) node;
}
}
{
public:
int data;
unsigned long link;
};
class xlist
{
xll *head,*tail;
xlist(){head = NULL;tail = NULL}
void insert(int);
};
void xlist :: insert (int ele)
{
xll *node = (xll*) malloc (sizeof(xll));
node->data = ele;
xll *temp = head,*prev = NULL;
while(temp != NULL)
{
next = (xll *) (temp->link ^ (unsigned long) prev);
prev = temp;
temp = next;
}
if(prev == NULL)
head = node;
else
{
node->link ^= (unsigned long) prev ^ (unsigned long) temp;
prev->link ^= (unsigned long) temp ^ (unsigned long) node;
temp->link ^= (unsigned long) prev ^ (unsigned long) node;
}
}
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- help implementing singly linked list (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why doesn't this remove the last node in a linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the C++ Forum
- Previous Thread: Dice rolling program... Output trouble
- Next Thread: I can't use one member function in another member function
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






