Ds
Ds
ASSIGNMENT 2
SECTION : SE
ROLL NO: 60
//QUESTION 1
#include <stdio.h>
#include <malloc.h>
int data;
} snode;
snode *p;
p=(snode*)malloc(sizeof(snode));
if (p != NULL)
p->data=n;
p->next = NULL;
if (tail == NULL)
return p;
tail->next = p;
tail = p;
else
return tail;
}
void display(snode *head, snode *tail)
if (head == NULL)
return;
display(head->next, tail);
printf("%d", head->data);
int main()
int ch, n;
do
scanf("%d", &ch);
if (ch == 1)
scanf("%d", &n);
if (head == NULL)
tail = head;
printf("Element Inserted\n");
else if (ch == 2)
if (head != NULL)
printf("Queue Underflow\n");
return 0;
//OUTPUT
1.Insert Element
2.Display in reverse
3.Exit
Element Inserted
1.Insert Element
2.Display in reverse
3.Exit
Element Inserted
1.Insert Element
2.Display in reverse
3.Exit
Element Inserted
1.Insert Element
2.Display in reverse
3.Exit
Element Inserted
1.Insert Element
2.Display in reverse
3.Exit
//QUESTION 2
#include <malloc.h>
#include <stdio.h>
int data;
} snode;
p= (snode *)malloc(sizeof(snode));
if (p != NULL)
p ->data = n;
p->next = top;
top =p;
else
return top;
{
if (top == NULL)
return;
disp(top->next);
int main()
int ch, n;
do
scanf("%d", &ch);
if (ch == 1)
scanf("%d", &n);
else if (ch == 2)
if (top != NULL)
else
printf("stack underflow\n");
}
//OUTPUT
1. Push
2. Display in reverse
3. Exit
Element pushed !
1. Push
2. Display in reverse
3. Exit
Element pushed !
1. Push
2. Display in reverse
3. Exit
Element pushed !
1. Push
2. Display in reverse
3. Exit
Stack status: 4 5 3
1. Push
2. Display in reverse
3. Exit
//QUESTION 3
#include<stdio.h>
#include<malloc.h>
int data;
} snode;
snode *p = NULL;
p=(snode*)malloc(sizeof(snode));
if (p != NULL)
p->data = n;
p->next = NULL;
if (*hd == NULL)
*hd = *tl = p;
else
(*tl)->next = p;
*tl = p;
else
int loc = 1;
*hd = temp->next;
free(temp) ;
return;
prev = temp;
temp = temp->next;
loc++;
if (temp == NULL)
return;
prev->next = temp->next;
free(temp);
printf("%d", hd->data);
hd = hd->next;
printf("%d\n", hd->data);
int main()
int ch, n;
do
scanf("%d", &ch);
if(ch == 1){
scanf("%d ",&n) ;
if (head == NULL)
continue;
scanf("%d", &n);
else if (ch == 3)
if (head = NULL)
continue;
disp(head, tail);
else if (ch == 4)
break;
else
printf("Invalid Choice!");
//output
MENU
1. Insert
3. Display
4. Exit
Element Inserted!
MENU
1. Insert
2. Delete a Node with Key
3. Display
4. Exit