Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include "stdlib.h"
- #include "stdio.h"
- struct Node {
- int data;
- struct Node* next;
- struct Node* prev;
- };
- struct Node* head;
- struct Node *newNode(int x) {
- struct Node* temp = malloc(sizeof(struct Node));
- temp->data = x;
- temp->prev = NULL;
- temp->next = NULL;
- return temp;
- }
- void InsertAtHead(int x) {
- struct Node* temp = newNode(x);
- if (head == NULL) {
- head = temp;
- return;
- }
- else {
- head->prev = temp;
- temp->next = head;
- head = temp;
- }
- }
- void Print() {
- struct Node* temp = head;
- while (temp != NULL) {
- printf("%d", temp->data);
- temp = temp->next;
- }
- printf("\n");
- }
- int main() {
- head = NULL;
- InsertAtHead(2);
- InsertAtHead(3);
- InsertAtHead(4);
- InsertAtHead(5);
- InsertAtHead(6);
- InsertAtHead(7);
- Print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement