Created
June 5, 2018 13:41
-
-
Save prameshbajra/d18b693abdd56289bf5cbceda525e8aa to your computer and use it in GitHub Desktop.
By - Pavan Yekabote
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 nde { | |
int data; | |
struct nde *link; | |
}; | |
typedef struct nde* Node; | |
Node getNode() | |
{ | |
Node x; | |
x = (Node)malloc(sizeof(struct nde)); | |
return x; | |
} | |
Node addNode(int data, Node head) | |
{ | |
Node temp = getNode(); | |
temp->data = data; | |
if(head == NULL) | |
{ | |
temp->link = temp; | |
return temp; | |
} | |
else | |
{ Node current = head; | |
while(current->link != head ) | |
{ | |
current = current->link; | |
} | |
current->link = temp; | |
temp->link = head; | |
} | |
return head; | |
} | |
void printNodes(Node head) | |
{ | |
Node current = head; | |
while(current->link != head ) | |
{ | |
printf(" %d",current->data); | |
current = current->link; | |
} | |
printf(" %d\n",current->data); | |
} | |
int main() | |
{ | |
Node head = NULL; | |
head = addNode(5,head); | |
head = addNode(7,head); | |
head = addNode(9, head); | |
printNodes(head); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment