Linked List Programs
Linked List Programs
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
typedef struct node* NODE;
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf("out of memory\n");
exit(0);
}
return x;
}
void freenode(NODE x)
{
free(x);
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *llink;
struct node *rlink;
};
typedef struct node* NODE;
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf("out of memory\n");
exit(0);
}
return x;
}
void freenode(NODE x)
{
free(x);
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
typedef struct node* NODE;
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf("out of memory\n");
exit(0);
}
return x;
}
void freenode(NODE x)
{
free(x);
}
if (last == NULL)
{
printf("\nList is empty.\n");
return last;
}
else
{
temp = last->link;
last->link = temp->link;
free(temp);
return last;
}
}
if (last == NULL)
{
temp->info = item;
temp->link = temp;
last = temp;
return temp;
}
else
{
temp->info = item;
temp->link= last->link;
last->link = temp;
last = temp;
return last;
}
}
if (last == NULL)
printf("\nList is empty.\n");
temp = last->link;
while(temp->link != last)
temp = temp->link;
temp->link = last->link;
last = temp;
}
do {
printf("\t %d", temp->info);
temp = temp->link;
} while (temp != last->link);
}
void main()
{
NODE last=NULL;
int choice, item;
//clrscr();
for(;;)
{
printf("\n1.INSERT FRONT\n2.INSERT REAR\n3.DELETE FRONT\n4.DELETE
REAR\n5.DISPLAY\n");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("Enter the item\n");
scanf("%d",&item);
last=insert_front(item,last);
break;
case 2:printf("Enter the item\n");
scanf("%d",&item);
last=insert_rear(item,last);
break;
case 3:last=delete_front(last);
break;
case 4:last=delete_rear(last);
break;
case 5:display(last);
break;
default:exit(0);
}
}
}