Professional Documents
Culture Documents
Assignment 1
Assignment 1
Accessing A user can access individual A user can access only one member
Members members at a given time. at a given time.
Size A Structure does not have a A Union does not have a separate
shared location for all of its location for every member in it. It
members. It makes the size of a makes its size equal to the size of
Structure to be greater than or the largest member among all the
equal to the sum of the size of its data members.
data members.
Value Altering Altering the values of a single When you alter the values of a
member does not affect the other single member, it affects the values
members of a Structure. of other members.
Storage of Value In the case of a Structure, there is In the case of a Union, there is an
a specific memory location for allocation of only one shared
every input data member. Thus, it memory for all the input data
can store multiple values of the members. Thus, it stores one value
various members. at a time for all of its members.
Initialization In the case of a Structure, a user In the case of a Union, a user can
can initialize multiple members only initiate the first member at a
at the same time. time.
Priority queue can be implemented using an array, a linked list, a heap data
structure, or a binary search tree. Among these data structures, heap data
structure provides an efficient implementation of priority queues.
The queue data structure follows the FIFO strategy, i.e., first in, first out,
whereas the priority queue only checks the priority of the elements for
retrieving the elements. Priority queues are implemented as container
adapters. It is a class that uses an encapsulated object of a specific container
class and deliver a specific set of member function to access the queue
elements.
Inserting an element into a priority queue (max-heap) is done by the following steps.
Peek operation returns the maximum element from Max Heap or minimum element from Min
Though the insertion and deletion in a deque can be performed on both ends, it
does not follow the FIFO rule. The representation of a deque is given as follows -
Types of deque
In input restricted queue, insertion operation can be performed at only one end,
while deletion can be performed from both ends.
In output restricted queue, deletion operation can be performed at only one end,
while insertion can be performed from both ends.
Q7) WHAT IS OVERFLOW AND UNDERFLOW AND SHOW HOW IT
WORKS IN THE LINKED LIST?
Overflow is the situation where you try to store a number that exceeds the value
range for the data type. When you try to store too large of a positive or negative
number, the binary representation of the number (remember that all values are
stored as a 0 and 1 pattern) is corrupted and you get a meaningless or erroneous
result.
Underflow occurs in floating point numbers and is the situation where in
numbers very close to zero, there are not enough significant digits to represent
the number exactly.
I have a created an example of an overflow and an underflow. Through these
examples, I am going to jump ahead and introduce something called macro
constants. These will help us explore overflows and underflows.
Macro constants
A macro constant is a name for a constant, typically written in all capitals, that is
created as a pre-processor directive. Since these are pre-processor directives,
before the compiler builds the program, the macro constant will be replaced with
an actual value. You can think of the macro constants as aliases or place holders
for the real values. We will discuss how you can create your own macro constants
in the next section.
The output
Q8) IMPLEMENT INFIX AND POSTFIX EXPRESSION.
OUTPUT: