0% found this document useful (0 votes)
22 views8 pages

Data Structures

The document describes a C program that implements a priority queue using a linked list to manage a to-do list. The program allows the user to add tasks to the list with priorities, display the list, search for tasks, delete the highest priority task, and update or delete existing tasks. The linked list implementation uses pointers and memory allocation to dynamically add and remove nodes from the priority queue as tasks are managed on the to-do list.

Uploaded by

Prajakta J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

Data Structures

The document describes a C program that implements a priority queue using a linked list to manage a to-do list. The program allows the user to add tasks to the list with priorities, display the list, search for tasks, delete the highest priority task, and update or delete existing tasks. The linked list implementation uses pointers and memory allocation to dynamically add and remove nodes from the priority queue as tasks are managed on the to-do list.

Uploaded by

Prajakta J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PRIORITY QUEUE AND IMPLEMENTATION OF LINKED LISTS:

TO DO LIST PROGRAM:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
struct block
{
int pr;
char val[100];
struct block *next;
}
*start;

void newdel(struct block*);

void del();

void push(char[100],int);

void update()
{
char task[100];
int new_pr,flag=0,choice;
struct block *temp;
temp=start;
if(temp->next==NULL)
{
printf("Enter one more task to update list!\n");
}
else if (start!=NULL)
{
printf("1. Delete\n");
printf("2. Update\n");
scanf("%d",&choice);
printf("Enter the task to Update/Delete\n");
scanf("%s",task);
if(choice==2)
{
printf("Enter New Priority\n");
scanf("%d",&new_pr);
}
while (temp!=NULL)
{
if (strcmp(temp->val,task)==0)
{
flag=1;
break;
}
else
{
flag=0;
}
temp=temp->next;
}
if (flag==1)
{
newdel(temp);
if(choice==2)
{
push(task,new_pr);
}
}
else
{
printf("Task Not Found\n");
}
}
else printf("List Is Empty\n");
}

void disp()
{
struct block *temp;
temp = start;
printf("\nTo-Do List:\n\n");
printf("\tTask\t\t\tPriority\n");
while(temp!=NULL)
{
printf("\t%s\t\t",temp->val);
printf("\t%d\t\n",temp->pr);
temp=temp->next;
}
printf("\n");
}

void search()
{
int flag=0;
char key_task[100];
struct block *temp;
temp=start;
if (start!=NULL)
{
printf("Enter Task Name:\n");
scanf("%s",key_task);
while ( temp!=NULL)
{
if ( strcmp(temp->val,key_task)==0)
{
flag=1;
break;
}
else flag=0;
temp=temp->next;
}
if (flag==1)
{
printf("Task %s found with Priority %d\n",temp->val,temp->pr);
}
else printf("Task not found\n");

}
else printf("List Is Empty\n");
}

void push(char temp1[100],int pri)


{
struct block *temp, *t;
temp = (struct block *)malloc(sizeof(struct block));
strcpy(temp->val,temp1);
temp->pr=pri;
temp->next=NULL;
if(start==NULL)
{
start = temp;
}
else if(start->pr>pri)
{
temp->next=start;
start=temp;
}
else
{
t=start;
while(t->next!=NULL && (t->next)->pr<=pri )
t=t->next;
temp->next=t->next;
t->next=temp;
}
}

void del()
{
if(start!=NULL)
{
printf("\n\tTask %s marked as DONE!\n",start->val);
start = start->next;
}
else printf("\nList Is Empty\n");
}

void newdel(struct block *delement)


{
struct block * temp2;
struct block * temp;
struct block * prev;
temp=start;
printf("Modified successfully!");
if(delement->next!=NULL)
{
temp2=delement->next;
while(temp->val!=delement->val)
{
prev=temp;
temp=temp->next;
}
free(delement);
prev->next=temp2;
}
else
{
while(temp->next!=NULL)
{
prev=temp;
temp=temp->next;
}
prev->next=NULL;
}
}

void main()
{
int ch,pr, check=1;
char temp1[100];
clrscr();
printf("\n\t\t\t DSU MICRO PROJECT\n\n\t\t\t TO-DO LIST\n\n\t");
while(check==1)
{
printf("\nIn To Do List Select:\n1. Add New Task\n2. Mark task done with Highest Priority\n3.
Display My Tasks\n4. Search for a Task\n5. Update Or Delete Any Task\n6. Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\nEnter Task And Its Priority: \n");
scanf("%s%d",temp1,&pr);
push(temp1,pr);
break;

case 2: del();
break;

case 3: disp();
break;

case 4: search();
break;

case 5: update();
break;

case 6: check=0;
break;

default: printf("Wrong Choice\n");


printf("\nPress 1 To Continue Or 0 To Stop\n");
scanf("%d",&check);
}
}
getch();
}
OUTPUT:

TO ADD TASK:

:
TASKS DISPLAYED:

TO SEARCH A TASK:

TO DELETE A TASK:
TO UPDATE A TASK:

You might also like