Professional Documents
Culture Documents
Name - Aryan Gupta Reg. No. 199301088 Section - B
Name - Aryan Gupta Reg. No. 199301088 Section - B
Ans.1)
Code –
// Heap Sort in C
#include <stdio.h>
// Heap sort
for (int i = n - 1; i >= 0; i--) {
swap(&arr[0], &arr[i]);
// Driver code
int main() {
int n;
printf("Enter array size: ");
scanf("%d",&n);
printf("Enter array elements:\n");
int a[n];
for(int i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf("Entered array:\n");
printArray(a,n);
heapSort(a, n);
Ans.2)
Code –
#include<stdio.h>
#include<malloc.h>
void insert();
void del();
void display();
struct node
{
int priority;
int info;
struct node *next;
}*start=NULL,*q,*temp,*new;
void del()
{
if(start==NULL)
{
printf("\nUnderflow\n");
}
else
{
new=start;
printf("\nDeleted element - %d\n",new->info);
start=start->next;
//free(start);
}
}
void display()
{
temp=start;
if(start==NULL)
printf("Empty queue\n");
else
{
if(temp!=NULL)
for(temp=start;temp!=NULL;temp=temp->next)
{
printf("\n%d priority =%d\n",temp->info,temp->priority);
//temp=temp->next;
}
}
}
Output –