LINEAR QUEUE with Diagram and C implementation.
Operations of LINEAR QUEUE
Drawback of LINEAR QUEUE
CIRCULAR QUEUE with Diagram and C implementation
Operations of CIRCULAR QUEUE
PRIORITY QUEUE with Diagram and C implementation
Operations of PRIORITY QUEUE
CASE STUDIES
EXAMPLES
A broadband antenna means the antenna with wideband radiation characteristics. To make a broadband antenna, we can use a helical, a biconical, a sleeve, a spiral, and a log-periodic antenna.
Infix to Postfix Conversion Using StackSoumen Santra
Infix to Postfix Conversion Using Stack is one of the most significant example of application of Stack which is an ADT (Abstract Data Type) based on LIFO concept.
A broadband antenna means the antenna with wideband radiation characteristics. To make a broadband antenna, we can use a helical, a biconical, a sleeve, a spiral, and a log-periodic antenna.
Infix to Postfix Conversion Using StackSoumen Santra
Infix to Postfix Conversion Using Stack is one of the most significant example of application of Stack which is an ADT (Abstract Data Type) based on LIFO concept.
Introduction, Array of structure, Passing structure to function, Passing array of structure to function, Structure within structure ( Nested Structure), Union, Pointer to structure
this discusses reflectarray antena and the difference between reflectarray and parabolic antenna , refelctarray antenna types,equation and applications and it's elements
Stack and its Applications : Data Structures ADTSoumen Santra
Stack is an Abstract Data Type (ADT), Last in First out (LIFO) concept.
Features of Stack: Abstract Data Type (ADT)
C implementations of Stack's Functions like push(), pop(), isEmpty(), isOverflow(), peep()
Stack Applications like Tower of Hanoi, Infix to Postfix Conversion, Postfix Evaluation, Parenthesis Checking etc.
Diagramatic Representation of Tower of Hanoi, Infix to Postfix Conversion & Postfix Evaluation
Sequential collection of elements of the same type
used to store a collection of data
consist of contiguous memory locations
lowest address corresponds to the first element and the highest address to the last element.
This is presentation, that covers all the important topics related to strings in python. It covers storing, slicing, format, concatenation, modification, escape characters and string methods.
The file attatched also includes examples related to the slides shown.
An Antenna is a transducer, which converts electrical power into electromagnetic waves and vice versa.
An Antenna can be used either as a transmitting antenna or a receiving antenna.
A transmitting antenna is one, which converts electrical signals into electromagnetic waves and radiates them.
A receiving antenna is one, which converts electromagnetic waves from the received beam into electrical signals.
In two-way communication, the same antenna can be used for both transmission and reception.
Basic Parameters
Frequency
Wavelength
Impedance matching
VSWR & reflected power
Bandwidth
Percentage bandwidth
Radiation intensity.
Introduction, Array of structure, Passing structure to function, Passing array of structure to function, Structure within structure ( Nested Structure), Union, Pointer to structure
this discusses reflectarray antena and the difference between reflectarray and parabolic antenna , refelctarray antenna types,equation and applications and it's elements
Stack and its Applications : Data Structures ADTSoumen Santra
Stack is an Abstract Data Type (ADT), Last in First out (LIFO) concept.
Features of Stack: Abstract Data Type (ADT)
C implementations of Stack's Functions like push(), pop(), isEmpty(), isOverflow(), peep()
Stack Applications like Tower of Hanoi, Infix to Postfix Conversion, Postfix Evaluation, Parenthesis Checking etc.
Diagramatic Representation of Tower of Hanoi, Infix to Postfix Conversion & Postfix Evaluation
Sequential collection of elements of the same type
used to store a collection of data
consist of contiguous memory locations
lowest address corresponds to the first element and the highest address to the last element.
This is presentation, that covers all the important topics related to strings in python. It covers storing, slicing, format, concatenation, modification, escape characters and string methods.
The file attatched also includes examples related to the slides shown.
An Antenna is a transducer, which converts electrical power into electromagnetic waves and vice versa.
An Antenna can be used either as a transmitting antenna or a receiving antenna.
A transmitting antenna is one, which converts electrical signals into electromagnetic waves and radiates them.
A receiving antenna is one, which converts electromagnetic waves from the received beam into electrical signals.
In two-way communication, the same antenna can be used for both transmission and reception.
Basic Parameters
Frequency
Wavelength
Impedance matching
VSWR & reflected power
Bandwidth
Percentage bandwidth
Radiation intensity.
An ordered collection of items from which items may be deleted from one end called the front and into which items may be inserted from other end called rear is known as Queue.
It is a linear data structure.
It is called the First In First Out (FIFO) list. Since in queue, the first element will be the first element out.
The power point presentation shows the Implementation of Queue operations using arrays and Linked List. Further, It also demonstrates about Circular queue operations.
HEAP SORT ILLUSTRATED WITH HEAPIFY, BUILD HEAP FOR DYNAMIC ARRAYS.
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.
Cell hole identification in carcinogenic segment using Geodesic Methodology: ...Soumen Santra
Indian Economic Association organized the 106th Annual conference at University of Delhi.
This ppt awarded as Best research paper in the theme of Research (including education) Data and Artificial Intelligence for development.
A conference lecture talk on medical image analysis using Machine learning algorithms. here the used algorithms based on Morphological assessment parameters. the used database is based on carcinoma. The conference organised by National Institute of Technology (NIT)- Patna indexed by IET digital library.
https://digital-library.theiet.org/content/conferences/10.1049/icp.2023.1467
Conference: 8th International Conference on Computing in Engineering and Technology (ICCET 2023)
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Tr...Soumen Santra
Optimization techniques: Ant Colony Optimization: Bee Colony Optimization: Traveling Salesman Problem
Features of Ant Colony
Features of Ant
Features of other Optimization Techniques
Algorithm
Flow Charts
A Novel Real Time Home Automation System with Google Assistance TechnologySoumen Santra
A Novel Real Time Home Automation System with Google Assistance Technology
IOT DEVICES FOR POWER CONSUMPTION
Abstract
Introduction
Previous Work
Proposal
Process Flow with Google Assistance
Flow-diagram
Equipment
Results
Conclusion
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
Features
JVM
Architecture
Security
Data Types
Class and Object
Program
First Java Application
Declaring and creating objects
Arrays
Constructors
this keyword
static keyword
Inheritance
Overriding
Access Modifiers
super keyword
final keyword
abstract classes
interfaces
Exceptions (error handling)
User Defining exceptions
Java : Components
Java : Features
Java : Security
Java better than C++
Basic Data Types
Applications : Types
Life Cycle of Java Code
Java Development Kit
Java Example
Mechanism of Applets
Significance of downloading Applets
Used Java Main Packages
Threads Advance in System Administration with LinuxSoumen Santra
Threads Advance in System Administration with Linux
Process Descriptor Handling
Kernel Stack
Pid_hash Table and Chained Lists
PID Hash Table Handling Functions and Macros
Wait Queues
Process Resource Limits
Task State Segment
System Calls
Pthread Operations
POSIX threads on GNU/Linux
Programs on Thread in C
Carrier Sense Multiple Access With Collision Detection (CSMA/CD) Details : Me...Soumen Santra
Media Access Protocol (MAC)
Carrier Sense Multiple Access With Collision Detection (CSMA/CD)
Definition
Introduction
Features
Principle
Flowchart
Collision Mechanism
COLLISION DETECTION METHODS
Slot Time
Non-Persistent CSMA/CD
Efficiency
Advantages
Disadvantages
Detail Discussion with Mathematical Formula
Code-Division Multiple Access (CDMA)
Definition
Features
Example
Example Diagram
Mechanisms
Chip Sequences Code
Walsh Tables: Chip Sequence Code Generation
CDMA: Representation of Data
CDMA : An Real Example
CDMA : Digital Signal Created
CDMA : Data on the Channel
CDMA: Decoding of composite signals in one station
CDMA : Advantages of Synchronous & Asynchronous
CDMA : Uses
PURE ALOHA : MEDIUM ACCESS CONTROL PROTOCOL (MAC): Definition : Types : DetailsSoumen Santra
MEDIUM ACCESS CONTROL PROTOCOL : PURE ALOHA
MAC PROTOCOL
PURE ALOHA
Definition
Types of ALOHA
PURE ALOHA & SLOTTED ALOHA
Features
Issues
Examples with Diagram
Flowchart
Vulnerable Time
Efficiency
Throughput
What is RFID ?
Components of RFID
RFID Tags & Readers
How does RFID work ?
Block Diagram
Applications of RFID
Security issues
Next-Generation RFID
Advantages
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION Soumen Santra
SPACE DIVISION MULTIPLE ACCESS (SDMA)
Definition : The communication channel encountered by this array of antennas.
advanced antenna technology.
Smart Antenna
Uplink Transmission
Downlink Transmission
Block Diagram
Features
Beam Frequency Reuse
Advantages
Disadvantages
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
2. DEFINITION OF QUEUE
• A Queue is an ordered collection ADT(Abstract Data Type) of items
from which items may be deleted at one end (FRONT) and into
which items may be inserted at the other end (REAR).
• The first element inserted into the queue is the first element to be
removed. The queue is sometimes called a FIFO (first-in first-out) list
as opposed to the stack, which is a LIFO (last-in first-out).
3. Queue
• Stores a set of elements in a particular order
• Stack principle: FIRST IN FIRST OUT
• = FIFO
• It means: the first element inserted is the first one to be
removed.
• The first one in line is the first one to be served
• Example
4. Queue Applications
• Real life examples
• Waiting in line for reservation
• Waiting on hold for tech support
• Applications related to Computer Science
• Threads scheduling & synchronization
• Job scheduling (e.g. Round-Robin algorithm for CPU allocation)
8. Declaration of a Queue
# define MAX 500 /* size of the queue items*/
typedef struct {
int front;
int rear;
int items[MAX];
}QUEUE;
9. QUEUE OPERATIONS
• Initialize the queue
• Insert to the rear of the queue
• Remove (Delete) from the front of the queue
• Is the Queue Empty
• Is the Queue Full
• What is the size of the Queue
10. Queue Example: Class Diagram Concept
+Queue()
+insert() : void
+remove() : long
+peekFront() : long
+isEmpty() : bool
+isFull() : bool
+size() : int
-maxSize : int
-queueArray [] : long
-front : int
-rear : int
-nItems : int
Queue
QueueApp
Interface1
11. INITIALIZE THE QUEUE
items[MAX-1]
. .
. .
.
items[1]
items[0] front=0
rear=-1
•The queue is initialized by having the rear set to -1, and front set to 0. Let us
assume that maximum number of the element we have in a queue is MAX size
elements as shown below.
12. insert(&Queue, ‘A’) Method
• an item (A) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2]
items[1]
items[0] A Front=0,
Rear=0
13. insert(&Queue, ‘B’) Method
• A new item (B) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2]
items[1] B Rear=1
items[0] A Front=0
14. insert(&Queue, ‘C’) Method
• A new item (C) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3]
items[2] C Rear=2
items[1] B
items[0] A Front=0
15. insert(&Queue, ‘D’) Method
• A new item (D) is inserted at the Rear of the queue
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B
items[0] A Front=0
16. Array-based Queue Implementation
• As with the array-based stack implementation, the array is
of fixed size
• A queue of maximum N elements
• Slightly more complicated
• Need to maintain CONTROL of both front and rear
Implementation 1
Implementation 2
17. Insert Operation of Queue using pointer
void insert(QUEUE *qptr, char x)
{
if(qptr->rear == MAX-1)
{
printf("Queue is full!");
exit(1);
}
else
{
qptr->rear++;
qptr->items[qptr->rear]=x;
}
}
18. char remove(&Queue) Method
• an item (A) is removed (deleted) from the Front of
the queue & return it as per datatype.
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] A
19. char remove(&Queue) Method
• Remove two items from the front of the queue.
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C Front=2
items[1] B
items[0] A
20. char remove(&Queue) Method
• Remove two items from the front of the queue.
items[MAX-1]
. .
. .
items[3] D Front=Rear=3
items[2] C
items[1] B
items[0] A
21. char remove(&Queue) Method
• Remove one more item from the front of the queue.
items[MAX-1]
. .
items[4] Front=4
items[3] D Rear=3
items[2] C
items[1] B
items[0] A
22. Remove Operation implementation in c
char remove(struct queue *qptr)
{
char p;
if(qptr->front > qptr->rear){
printf("Queue is empty");
exit(1);
}
else
{p=qptr->items[qptr->front];
qptr->front++;
return p;
}
}
23. INSERT / REMOVE ITEMS : Drawback of Linear Queue
• Assume that the rear= MAX-1
•What happens if we want to insert a new
item into the queue?
items[MAX-1] X rear=MAX-1
. .
. .
items[3] D front=3
items[2] C
items[1] B
items[0] A
24. INSERT / REMOVE ITEMS
• What happens if we want to insert a new item F into the
queue?
• Although there is some empty space, the queue is full.
• One of the methods to overcome this problem is to shift all
the items to occupy the location of deleted item.
26. REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] B Front=1
items[0] B
27. REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] C
items[1] C
items[0] B
28. REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D Rear=3
items[2] D
items[1] C
items[0] B
29. REMOVE ITEM : Example
items[MAX-1]
. .
. .
items[3] D
items[2] D Rear=2
items[1] C
items[0] B
30. Modified Remove Operation implementation
in C
char remove(struct queue *qptr)
{
char p;
int i;
if(qptr->front > qptr->rear){
printf("Queue is empty");
exit(1);
}
else
{p=qptr->items[qptr->front];
for(i=1;i<=qptr->rear;i++)
qptr->items[i-1]=qptr->items[i];
qptr->rear--
return p;
}
}
31. INSERT / REMOVE ITEMS
• Since all the items in the queue are required to shift when an
item is deleted, this method is not preferred.
• The other method is circular queue.
• When rear = MAX-1, the next element is entered at items[0] in
case that spot is free.
32. How to Initialize the queue
items[6] front=rear=6
items[5]
items[4]
items[3]
items[2]
items[1]
items[0]
33. Insert operation in Circular Queue
items[6] front=6
items[5]
items[4]
items[3]
items[2]
items[1]
items[0] 1 rear=0
Insert 1,2,3 to the rear of the queue.
34. Insert operation in Circular Queue
items[6] front=6
items[5]
items[4]
items[3]
items[2]
items[1] 2 rear=1
items[0] 1
Insert 1,2,3 to the rear of the queue.
35. Insert operation in Circular Queue
• Insert 1,2,3 to the rear of the queue.
items[6] front=6
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2
items[0] 1
36. Remove items from circular queue
• Remove two items from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2
items[0] 1 front=0
37. Remove items from circular queue
• Remove two items from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=2
items[1] 2 front=1
items[0] 1
38. Remove items from circular queue
• Remove one more item from the queue.
items[6]
items[5]
items[4]
items[3]
items[2] 3 rear=front=2
items[1] 2
items[0] 1
39. Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 4,5,6,7 to the queue.
items[6] 7 rear=6
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 2
items[0] 1
40. Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 8 and 9 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 2
items[0] 8 rear=0
41. Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 8 and 9 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] 3 front=2
items[1] 9
items[0] 8 rear=0
42. Insert operation in Circular Queue:
Overcome Drawback of Linear Queue
• Insert 10 to the queue.
items[6] 7
items[5] 6
items[4] 5
items[3] 4
items[2] ?? front=rear=2
items[1] 9
items[0] 8
43. Implementation of a Circular Queue in C
#define MAX 10 /* size of the queue items*/
typedef struct {
int front;
int rear;
int items[MAX];
}QUEUE;
QUEUE Q;
Q.front = MAX-1;
Q.rear= MAX-1;
44. EMPTY QUEUE
[2] [3] [2] [3]
[1] [4] [1] [4]
[0] [5] [0] [5]
front = 0 front = 0
rear = 0 rear = 3
B
A
C
Implementation 2:Cyclic View
Can be seen as a circular queue
45. FULL QUEUE FULL QUEUE
[2] [3] [2] [3]
[1] [4][1] [4]
[0] [5] [0] [5]
front =0
rear = 5
front =4
rear =3
B C
A D
E F E
G
H I
Advantage of Circular Queue:
How to test when queue is UNDERFLOW?
How to test when queue is OVERFLOW?
46. Implementation of Insert Operation for
Circular Queue in C
void insert(QUEUE *qptr, char x)
{
if(qptr->rear == MAX-1)
qptr->rear=0;
else
qptr->rear++;
/* or qptr->rear=(qptr->rear+1)%MAX) */
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=x;
}
47. Implementation of Remove Operation
for Circular Queue in C
char remove(struct queue *qptr)
{
if(qptr->front == qptr->rear){
printf("Queue underflow");
exit(1);
}
if(qptr->front == MAX-1)
qptr->front=0;
else
qptr->front++;
return qptr->items[qptr->front];
}
48. #include <stdlib.h>
#include <stdio.h>
#define MAX 50
#define TRUE 1
#define FALSE 0
typedef struct
{
int items[MAX];
int front , rear ;
} Q;
void queinsert( Q * , int);
int quedelete(Q *);
int isempty(Q *);
EXAMPLE in C
49. int main()
{
char operation;
int x;
Q q;
q.front = q.rear = MAX - 1;
do
{
printf("%sn",“Queue Operation type I(Insert) D(Delete) or E(Exit) ");
scanf("n%c",&choice);
switch (choice) {
case 'I’: printf("%sn","Insert an element");
scanf("n%d",&x);
qinsert(&q , x);
break;
case 'D’: x=qdelete(&q);
printf("n %d is deleted n",x);
break;
default: printf(“Incorrect Operation typen”);
break;
}
}
while (choice != 'E’&&choice!='e');
return 0;
}
50. int isempty(Q *qptr)
{
return((qptr->front == qptr->rear) ? TRUE : FALSE);
}
int qdelete(Q *qptr)
{
if (empty(qptr)) {
printf("Queue underflow ");
exit(1);
}
qptr->front=(qptr->front+1)%(MAX)
return(qptr->items[qptr->front]);
}
void qinsert(Q *qptr , int x)
{
/* make room for new element */
printf("n %d is inserted n",x);
qptr->rear=(qptr->rear+1)%(MAX)
if (qptr->rear == qptr->front) {
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear] = x;
return;
}
51. #include<stdio.h>
#include<stdlib.h>
#define MAX 5 /* size of the queue items*/
typedef struct{
int front;
int rear;
float items[MAX];
}Q;
void qinsert(Q *, float);
float qdelete(Q *);
void display( Q *);
void clear( Q *);
void menu();
52. int main()
{
int choice;
float x;
Q q;
q.front = M-1;
q.rear= MAX-1;
do{
menu();
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the item to be inserted:");
scanf("%f",&x);
insert(&q,x);
break;
case 2: x=remove(&q); printf("nRemoved item:%f",x);
break;
case 3: display(&q);
break;
case 4: clear(&q);
break;
default: printf("nWrong entry, Try again!!");
break;
}
}while(choice != 5);
return 0;
}
53. void menu()
{
printf("Press 1 to insert n");
printf("Press 2 to remove n");
printf("Press 3 to display n");
printf("Press 4 to clear n");
printf("Press 5 to quitn");
printf("nnEnter your choice:n");
}
void insert(q *qptr, float x)
{
if(qptr->rear == MAXQ-1)
qptr->rear=0;
else
qptr->rear++;
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=x;
}
60. PRIORITY QUEUES
• The priority queue is a data structure in which internally
ordering of the elements determines the results of its basic
operations.
• An ascending priority queue is a combination of items with
priority into which items can be inserted arbitrarily and from
which only the smallest item can be removed. On the other
hand a descending priority queue allows only the largest item to
be removed.
• We use process.h for operation.
61. Priority QUEUE Operations
• Insertion
• The insertion in Priority queues is the same as in non-priority
queues.
• Deletion
• Deletion requires a search for the element of highest priority
and deletes the element with highest priority. The following
methods can be used for deletion/removal from a given
Priority Queue:
• An empty indicator replaces deleted elements.
• After each deletion elements can be moved up in the array
decrementing the rear.
• The array in the queue can be maintained as an ordered
circular array
62. Priority Queues Features
• Specialized data structure.
• Same as Queue, having front and rear.
• Items are deleted from the front.
• Items are ordered by priority value so that the item
with the lowest key (or highest) is always at the
front.
• Items are inserted in proper position to maintain
the order of ascending or descending.
63. Priority Queue : Class Diagram
+Queue()
+insert() : void
+remove() : long
+peekMin() : long
+isEmpty() : bool
+isFull() : bool
-maxSize : int
-queueArray [] : long
-nItems : int
PrioityQ
PriorityQApp
Interface1
64. Priority Queue Implementation in C
#define MAX 10 /* size of the queue items*/
typedef struct {
int front, rear;
int items[MAX];
}PQ;
65. int PQremove(Q *qptr)
{
int small, loc, f, i;
f=qptr->front;
if(qptr->front == qptr->rear){
printf("Queue underflow");
exit(1);
}
small = qptr->items[(qptr->front+1)%MAX];
loc = (qptr->front+1)%MAX;
(qptr->front++)%MAX; /* Circular increment*/
while(qptr->front != qptr->rear){
if(qptr->items[(qptr->front+1)%MAX] <small){
small = qptr->items[(qptr->front+1)%MAX];
loc = (qptr->front+1)%MAX;
}
qptr->front =(qptr->front+1)%MAX;
}
66. while(loc != qptr->rear){
qptr->items[loc] = qptr->items[(loc+1)%MAX];
(loc++)%MAX;
}
qptr->front=f;
if(qptr->rear == 0) /*Decrement rear after removing one
item*/
qptr->rear = MAX -1;
else
qptr->rear--;
return smallest;
}
67. Insert Operation of Priority Queue implemented in C
void insert(struct q *qptr, int item)
{
qptr->rear = (qptr->rear++)%MAX; /*Circular
increment*/
if(qptr->rear == qptr->front){
printf("Queue overflow");
exit(1);
}
qptr->items[qptr->rear]=item;
}
68. void enqueue(pqnode front, pqnode rear, element x)
{
pqnode temp =(pqnode) malloc(sizeof (queue));
if (IS_FULL(temp))
{
printf(“ The memory is fulln”);
exit(1);
}
temp->data = x;
temp->next= NULL;
if (front) { (rear) -> next= temp;}
else front = temp;
rear = temp;
Case Study: List-based Queue Implementation in C: insertion
69. int dequeue(pqnode front)
{
pqnode temp = front;
int x;
if (IS_EMPTY(front))
{
printf(“The queue is emptyn”);
exit(1);
}
x = temp->data;
front = temp->next;
free(temp);
return x;
}
Case Study: List-based Queue
Implementation in C: Deletion
70. Stack vs. Queue vs. Array
• Stack & Queue vs. Array
• Arrays are homogeneous data storage structures while
stacks and queues are derived ADT data storage
structures.
• Stack – ADT that allows push, peep and pop.
• Queue - ADT that allows enqueue and dequeue.
• In an array any item can be accessed through
index, while in these data structures access is
restricted.
71. Real world example of Queue
<?xml version = "1.0"?>
<!-- An author -->
<author>
<name gender = "male">
<first> Art </first>
<last> Gentleman </last>
</name>
</author>