Skip to content

Instantly share code, notes, and snippets.

@prameshbajra
Created June 5, 2018 13:41
Show Gist options
  • Save prameshbajra/d18b693abdd56289bf5cbceda525e8aa to your computer and use it in GitHub Desktop.
Save prameshbajra/d18b693abdd56289bf5cbceda525e8aa to your computer and use it in GitHub Desktop.
By - Pavan Yekabote
#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