Professional Documents
Culture Documents
Akhil
Akhil
if(head == NULL) {
printf("List is empty\n");
return;
while(current != NULL) {
current = current->next;
printf("\n");
}
Q6
(B)pop operation
void pop()
{
if (top >= 0)
{
top--;
}
else
{
cout << "Stack Underflow " << endl;
}
}
(C)peep operation
int peak()
{
if (top >= 0)
{
return arr[top];
}
else
{
cout << "Stack is empty" << endl;
return -1;
}
}
void display() {
if(top>=0) {
cout<<"Stack elements are:";
for(int i=top; i>=0; i--)
cout<<stack[i]<<" ";
cout<<endl;
} else
cout<<"Stack is empty";
}
Q2(a) insertion
void insert(struct node * ptr, int item) {
(b)deletion
void deleteNode(struct node * ptr) {
if (front == NULL) {
printf("Underflow");
return;
} else {
ptr = front;
front = front - > next;
free(ptr);
}
}
(c) display
void display()
ptr = front;
if(front == NULL)
{
printf("\nEmpty queue\n");
else
while(ptr != NULL)
Q1
arr[rear] = value;
return true;
}
(b) deletion
int dequeue()
{
if (front == -1)
{
cout << "Queue is empty " << endl;
return -1;
}
else
{
front++;
}
return ans;
}
(C) display
void display()
int i=front;
else
while(i<=rear)
printf("%d,", queue[i]);
i=(i+1)%max;