Skip to content

Instantly share code, notes, and snippets.

@imran-parray
Created September 20, 2017 06:53
Show Gist options
  • Save imran-parray/2d8da3113bdcae132035ba5de78f36a4 to your computer and use it in GitHub Desktop.
Save imran-parray/2d8da3113bdcae132035ba5de78f36a4 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *link;
};
typedef struct Node node;
node *first;
//first=NULL;
//INSERT FUNCTION
insert_front(int item)
{
node *temp;
temp=(node*)malloc(sizeof(node));
temp->data=item;
temp->link=NULL;
if(first==NULL)
first=temp;
else
{
temp->link=first;
first=temp;
}
}
//DELETE FUNCTION
delete_front()
{
node *cur;
if(first==NULL)
printf("No Elements to Delete\n");
else
{
printf("Deleted item %d ",first->data);
cur=first;
first=first->link;
free(cur);
}
}
//DISPLAY FUNCTION
display()
{
node *temp;
if(first==NULL)
printf("No Elements to Print\n");
else
{
temp=first;
printf("Elements are ");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->link;
}
}
}
//MAIN FUNCTIONS.s
void main()
{
int a,ch;
first=NULL;
while(1)
{
printf("\n\nEnter Your Choice\n 1-Insert\n2-Delete\n3-Display\n4-Exit:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("Enter The element to be inserted\n");
scanf("%d",&a);
insert_front(a);
}
break;
case 2:delete_front(); break;
case 3:display(); break;
case 4: printf("Invalid Option Exiting The programm\n");exit(1);break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment