# Double Linked List Code

```c
struct DoubleNode {
    int data;
    struct DoubleNode* prev;
    struct DoubleNode* next;
};

// Function to create a new double node
struct DoubleNode* createDoubleNode(int data) {
    struct DoubleNode* newNode = (struct DoubleNode*)malloc(sizeof(struct DoubleNode));
    if (newNode != NULL) {
        newNode->data = data;
        newNode->prev = NULL;
        newNode->next = NULL;
    }
    return newNode;
}

// Function to insert a new double node at the beginning of the list
void insertDoubleAtBeginning(struct DoubleNode** head, int data) {
    struct DoubleNode* newNode = createDoubleNode(data);
    if (newNode != NULL) {
        if (*head != NULL) {
            (*head)->prev = newNode;
            newNode->next = *head;
        }
        *head = newNode;
    }
}

// Function to insert a new double node at the end of the list
void insertDoubleAtEnd(struct DoubleNode** head, int data) {
    struct DoubleNode* newNode = createDoubleNode(data);
    if (newNode != NULL) {
        if (*head == NULL) {
            *head = newNode;
        } else {
            struct DoubleNode* temp = *head;
            while (temp->next != NULL) {
                temp = temp->next;
            }
            temp->next = newNode;
            newNode->prev = temp;
        }
    }
}

// Function to display the elements of the double linked list
void displayDoubleList(struct DoubleNode* head) {
    printf("Doubly Linked List: ");
    struct DoubleNode* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}

// Function to free the memory used by the double linked list
void freeDoubleList(struct DoubleNode* head) {
    struct DoubleNode* temp;
    while (head != NULL) {
        temp = head;
        head = head->next;
        free(temp);
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.introtoc.com/session-10/double-linked-list-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
