csll
csll
#include<stdio.h>
#include<malloc.h> // for malloc and free()
#include<stdlib.h>
struct node // structure of a node
{
int data; // data part
struct node *next; // address(points to next) part
} typedef (node); // node is a user defined data type(here)
//func prototypes
node* getnode();
void menu();
void insert_beg();
void delete_beg();
void peek();
void display();
node* start = NULL; // start points to first node
int main() // main function
{
int op;
do{
menu();
scanf("%d", &op);
switch(op)
{
case 0: exit(0);
case 1: insert_beg(); break;
case 2: delete_beg(); break;
case 3: peek(); break;
case 4: display(); break;
default: printf("Invalid Choice!");
break;
}
}while(1);
return 0;
}
node * getnode() // create a new node
{
node * temp; // temp is a pointer to node
temp = (node *)malloc(sizeof(node)); // allocate memory for a node
return temp; // return address of the node
}
void insert_beg() // insert at beginning
{
node *t, *p; // t and p are pointers to node
t = getnode(); // create a new node t
int x;
printf("enter element to insert\n");
scanf("%d", &x);
t->data = x; // store data in t
if (start == NULL) // empty list
{
start = t;
t->next = start; // point to itself to make it circular
printf("%d Inserted\n", start->data);
}
else // more than one node
{
p = start;
while (p->next != start) {
p = p->next;