Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- struct node {
- int data;
- unsigned long ptrOffset;
- };
- struct xorList {
- struct node* head;
- struct node* tail;
- };
- struct xorList* InitList(int data, int data2) {
- struct node* head = malloc(sizeof(struct node));
- struct node* tail = malloc(sizeof(struct node));
- head->ptrOffset = (unsigned long)((unsigned long)NULL ^ (unsigned long)tail);
- head->data = data;
- tail->ptrOffset = (unsigned long)((unsigned long)head ^ (unsigned long)NULL);
- tail->data = data2;
- struct xorList* list = malloc(sizeof(struct xorList));
- list->head = head;
- list->tail = tail;
- return list;
- }
- void Append(struct node* head, struct node* tail, int data) {
- struct node* newNode = malloc(sizeof(struct node));
- newNode->ptrOffset = (unsigned long)((unsigned long) head ^ (unsigned long)tail);
- newNode->data = data;
- }
- void main(){
- struct xorList* list = InitList(1, 2);
- //Append(head, 2);
- int count = 0;
- struct node* current = list->head;
- struct node* begin = list->head;
- struct node* prev = NULL;
- while (current != NULL) {
- count++;
- if (current == begin) {
- current = (struct node*)((unsigned long)prev ^ current->ptrOffset);
- }
- else {
- current = (struct node*)((unsigned long)prev ^ current->ptrOffset);
- }
- }
- printf("%d", count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement