#include<stdio.h>
#include<stdlib.h>
struct dll{
int data;
struct dll* previous;
struct dll* next;
};
struct dll* insertAtBeginning(int a, struct dll* head){
if(head == NULL){
head->data = a;
head->previous = NULL;
head->next = NULL;
return head;
}
else{
struct dll *first;
first
= (struct dll
*) malloc( sizeof(struct dll
)); first->data = a;
first->next = head;
head->previous = first;
first->previous = NULL;
head = first;
// free(first);
return head;
}
}
void display_from_first(struct dll* head){
struct dll *temp;
temp = head;
printf("\nThe linked list contains: "); while(temp != NULL) {
printf("%d------>",temp
->data
); temp = temp->next;
}
}
int main(){
int i = 0;
struct dll *head1, *tail1;
head1
= (struct dll
*) malloc( sizeof(struct dll
)); head1->next = NULL;
head1->previous = NULL;
for(i=0; i<10; i++){
head1= insertAtBeginning(i, head1);
}
display_from_first(head1);
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CgpzdHJ1Y3QgZGxsewogICAgaW50IGRhdGE7CiAgICBzdHJ1Y3QgZGxsKiBwcmV2aW91czsKICAgIHN0cnVjdCBkbGwqIG5leHQ7Cn07CgoKc3RydWN0IGRsbCogaW5zZXJ0QXRCZWdpbm5pbmcoaW50IGEsIHN0cnVjdCBkbGwqIGhlYWQpewoKICAgIGlmKGhlYWQgPT0gTlVMTCl7CiAgICAgICAgaGVhZC0+ZGF0YSA9IGE7CiAgICAgICAgaGVhZC0+cHJldmlvdXMgPSBOVUxMOwogICAgICAgIGhlYWQtPm5leHQgPSBOVUxMOwogICAgICAgIHJldHVybiBoZWFkOwogICAgfQogICAgZWxzZXsKICAgICAgICBzdHJ1Y3QgZGxsICpmaXJzdDsKICAgICAgICBmaXJzdCA9IChzdHJ1Y3QgZGxsKikgbWFsbG9jKCBzaXplb2Yoc3RydWN0IGRsbCkpOwogICAgICAgIGZpcnN0LT5kYXRhID0gYTsKICAgICAgICBmaXJzdC0+bmV4dCA9IGhlYWQ7CiAgICAgICAgaGVhZC0+cHJldmlvdXMgPSBmaXJzdDsKICA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