C Program to insert/delete/traverse/display XOR Linked List
Here is the C Program to insert/delete/traverse/display XOR Linked List.XOR linked list is said to be memory efficient version of doubly linked list.
_________________________________________________________________________________
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *ptr;
};
struct Node* XOR(struct Node *a,struct Node *b){
return (struct node*) ((unsigned int) (a) ^ (unsigned int) (b));
}
void insertIntoXORLL(struct Node **head,int pos,int data){
struct Node *newNode=(struct Node*)malloc(sizeof(struct Node));
newNode->data=data;
if(*head==NULL){//Insert first Node
newNode->data=data;
newNode->ptr=NULL;
*head=newNode;
}else{
struct Node *current=*head;
struct Node *previous=NULL,*next=NULL;
struct Node *nextNode=NULL;
if(pos<=1){
newNode->ptr=XOR(previous,*head);
nextNode=XOR((*head)->ptr,previous);
(*head)->ptr=XOR(newNode,nextNode);
*head=newNode;
}else if(pos>1){
int count=1;
while(current!=NULL &&…
_________________________________________________________________________________
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *ptr;
};
struct Node* XOR(struct Node *a,struct Node *b){
return (struct node*) ((unsigned int) (a) ^ (unsigned int) (b));
}
void insertIntoXORLL(struct Node **head,int pos,int data){
struct Node *newNode=(struct Node*)malloc(sizeof(struct Node));
newNode->data=data;
if(*head==NULL){//Insert first Node
newNode->data=data;
newNode->ptr=NULL;
*head=newNode;
}else{
struct Node *current=*head;
struct Node *previous=NULL,*next=NULL;
struct Node *nextNode=NULL;
if(pos<=1){
newNode->ptr=XOR(previous,*head);
nextNode=XOR((*head)->ptr,previous);
(*head)->ptr=XOR(newNode,nextNode);
*head=newNode;
}else if(pos>1){
int count=1;
while(current!=NULL &&…