Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary queue

Rating
-
Sold
-
Pages
5
Uploaded on
27-05-2023
Written in
2022/2023

In these comprehensive notes on data structures in C, you will gain a deep understanding of the fundamental concepts and practical implementation techniques. Whether you're a beginner or an experienced programmer, these notes will equip you with the knowledge and skills to design and manipulate data structures effectively. Explore topics such as arrays, linked lists, stacks, queues, trees, graphs, and more, as you discover how to optimize memory usage and enhance program efficiency. With clear explanations, examples, and code snippets, these notes will empower you to build efficient solutions and elevate your proficiency in data structure manipulation using the C programming language.

Show more Read less
Institution
Course

Content preview

QUEUE
A queue is a linear data structure that follows the First-In-
First-Out (FIFO) principle. It is an ordered collection of
elements in which an element is inserted at one end (rear)
and removed from the other end (front). Think of it as a
queue of people waiting in line, where the first person who
arrives is the first one to leave. Key characteristics of a
queue:

Enqueue: Adding an element to the rear of the queue.
Dequeue: Removing an element from the front of the queue.
Front: The element at the front of the queue, which will be
dequeued next.
Rear: The element at the rear of the queue, where new
elements are enqueued.
Empty: Checking if the queue is empty.
Size: The number of elements currently in the queue.
Operations on a queue:

Enqueue: Add an element to the rear of the queue.
Dequeue: Remove the element from the front of the queue.
Front: Retrieve the element at the front of the queue
without removing it.
IsEmpty: Check if the queue is empty.
Size: Get the current number of elements in the queue.
Queues can be implemented using arrays or linked lists. In
an array-based implementation, a fixed-size array is used,
and the front and rear pointers are maintained to keep track
of the elements. In a linked list-based implementation, each
element (node) contains the value and a reference to the
next node, and the front and rear pointers are maintained
as references to the first and last nodes, respectively

1. IMPLEMENTATION AND OPERATIONS ON QUEUE
USING ARRAY AND LINKED LIST
Implementation of Queue using an Array:
1. Define a fixed-size array to store the elements of the
queue.
2. Initialize two variables: front and rear, both initially set to
-1.
3. front keeps track of the index of the front element, and
rear keeps track of the index of the rear element.
4. To enqueue an element, increment the rear and insert the
element at the rear index in the array.
5. To dequeue an element, increment the front and remove
the element at the front index from the array.
6. Implement isEmpty() to check if the queue is empty by
checking if front is equal to rear.
7. Implement isFull() to check if the queue is full by
checking if rear is equal to the size of the array minus 1.

, 8. Implement getFront() to retrieve the element at the front
index without removing it.
9. Implement getSize() to return the current number of
elements in the queue.

Implementation of Queue using a Linked List:
1. Define a Node structure with two fields: data and next.
2. Create two pointers: front and rear, initially set to null.
3. front points to the first node in the linked list (the front of
the queue), and rear points to the last node (the rear of the
queue).
4. To enqueue an element, create a new node and assign
the data to it. If the queue is empty, set both front and rear
to the new node. Otherwise, update the next pointer of the
current rear node to the new node and update the rear
pointer to the new node.
5. To dequeue an element, if the queue is empty (front is
null), return an error. Otherwise, store the data of the front
node, move the front pointer to the next node, and free the
memory of the dequeued node.
6. Implement isEmpty() to check if the queue is empty by
checking if front is null.
7. Implement getFront() to retrieve the element at the front
without removing it.
8. Implement getSize() by traversing the linked list and
counting the number of nodes.

The operations for both implementations (array and linked
list) include enqueue, dequeue, isEmpty, getFront, and
getSize. These operations allow you to add elements to the
rear, remove elements from the front, check if the queue is
empty, retrieve the front element, and get the current size
of the queue.

2. DEQUEUE
A dequeue, also known as a double-ended queue, is a data
structure that allows insertion and removal of elements
from both ends. It combines the properties of a stack (LIFO -
Last In, First Out) and a queue (FIFO - First In, First Out).

The name "double-ended queue" signifies that you can
enqueue (add) or dequeue (remove) elements from both the
front and the rear of the queue.

Key operations on a dequeue include:

1. EnqueueFront: Adds an element to the front of the
dequeue.
2. EnqueueRear: Adds an element to the rear of the
dequeue.
3. DequeueFront: Removes and returns the element from
the front of the dequeue.

Written for

Course

Document information

Uploaded on
May 27, 2023
Number of pages
5
Written in
2022/2023
Type
SUMMARY

Subjects

$14.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
anjithaav

Get to know the seller

Seller avatar
anjithaav university institute of technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
14
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions