Created
August 10, 2019 14:06
-
-
Save Rajssss/c45d0b2fe6de1e4396df37bee5309ee4 to your computer and use it in GitHub Desktop.
C programm of Doubly Linked List + Circular Linked List, With Display and Reverse Display capabilities...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<stdlib.h> | |
| struct Node | |
| { | |
| int A; | |
| struct Node *next; | |
| struct Node *prev; | |
| } *first, *last; | |
| typedef struct Node Node; | |
| int Create(); | |
| void Display(); | |
| void RevDisplay(); | |
| void Circular(); | |
| int main(void) | |
| { | |
| int option; | |
| printf("Enter value=>"); | |
| first = (Node*)malloc(sizeof(Node)); | |
| scanf("%d", &first->A); | |
| first->next = 0; | |
| first->prev = 0; | |
| last = first; | |
| printf("Do you wanna add more?\n\t1. Yes\n\t2. No\n\t=>"); | |
| scanf("%d", &option); | |
| while(option == 1) | |
| { | |
| last = Create(first); | |
| printf("Do you wanna add more?\n\t1. Yes\n\t2. No\n\t=>"); | |
| scanf("%d", &option); | |
| } | |
| printf("Linked List is=> "); | |
| Display(first); | |
| printf("\nReverse Linked List is => "); | |
| RevDisplay(last); | |
| last->next = first; | |
| first->prev = last; | |
| printf("\nCircular Linked List is => "); | |
| Circular(first); | |
| return 0; | |
| } | |
| int Create(Node* first) | |
| { | |
| Node *temp = first, *newNode; | |
| newNode = (Node*)malloc(sizeof(Node)); | |
| printf("Enter value =>"); | |
| scanf("%d", &newNode->A); | |
| newNode->next = 0; | |
| while(temp->next != 0) | |
| temp = temp->next; | |
| temp->next = newNode; | |
| newNode->prev = temp; | |
| return (newNode); | |
| } | |
| void Display(Node *first) | |
| { | |
| if(first) | |
| { | |
| //Display(first->next); //Reverse Print | |
| printf("%d", first->A); | |
| Display(first->next); // Normal Print | |
| } | |
| } | |
| void RevDisplay(Node *last) | |
| { | |
| if(last) | |
| { | |
| printf("%d", last->A); | |
| RevDisplay(last->prev); | |
| } | |
| } | |
| void Circular(Node *ptr) | |
| { | |
| do | |
| { | |
| printf("%d", ptr->A); | |
| ptr = ptr->next; | |
| }while(ptr!=first); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment