Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Unit-2 - Data Structures Using C

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Unit-2 - Data Structures Using C

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Data Structures using C Init - II

STACKS
Definition of stack

A stack is a linear structure in which addition or deletion of elements takes place at all same end.
This end is often called the top of stack. For example, a stack of plates, a stack of coins, etc.,

As the items this type of data structure can be added or removed from the top, it means the last
item so be added to the stack is the first item to be removed.

Therefore, stacks are also called Last In First Out (LIFO) lists.

Operations on stack

The stack is basically performed two operations PUSH and POP.

Push and pop are the operations that are provided for insertion of an element into the stack and
the removal of an element from the stack, respectively.

PUSH() PUSH operation performed for the adding item to the stack.
POP() POP operation performed for removing an item from a stack.

Implementation of Stack through Array

A stack data structure can be implemented using one dimensional array. This implementation is
very simple, just define a one dimensional array of specific size and insert or delete the values
into that array by using LIFO principle with the help of a variable 'top'.

First follow the below steps to create an empty stack.

1. Include all the header files which are used in the program and define a
constant 'SIZE' with specific value.
2. Declare all the functions used in stack implementation.
3. Create a one dimensional array with fixed size (int stack[SIZE])
4. Define a integer variable 'top' and initialize with '-1'. (int top = -1)
5. In main method display menu with list of operations and make suitable function calls to
perform operation selected by the user on the stack.

1
Data Structures using C Init - II

push(value)

In a stack, push() is a function used to insert an element into the stack. In a stack, the new
element is always inserted at top position. Push function takes one integer value as parameter
and inserts that value into the stack. We can use the following steps to push an element on to the
stack...

1. Check whether stack is FULL. (top == SIZE-1)

2. If it is FULL, then display "Stack is FULL!!! Insertion is not possible!!!" and terminate
the function.

3. If it is NOT FULL, then increment top value by one (top++) and set stack[top] to value
(stack[top] = value).

pop()

In a stack, pop() is a function used to delete an element from the stack. In a stack, the element is
always deleted from top position. Pop function does not take any value as parameter. We can
use the following steps to pop an element from the stack...

1. Check whether stack is EMPTY. (top == -1)

2. If it is EMPTY, then display "Stack is EMPTY!!! Deletion is not possible!!!" and


terminate the function.

3. If it is NOT EMPTY, then delete stack[top] and decrement top value by one (top--).

/* Implementation of Stack through Array */

#include<stdio.h>
#include<conio.h>

#define SIZE 10

void push(int);
void pop();
void display();

int stack[SIZE], top = -1;

void main()
{
int value, choice;
clrscr();
while(1){
printf("\n\n***** MENU *****\n");
printf("1. Push\n2. Pop\n3. Display\n4. Exit");

2
Data Structures using C Init - II

printf("\nEnter your choice: ");


scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the value to be insert: ");
scanf("%d",&value);
push(value);
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nWrong selection!!! Try again!!!");
}
}
}
void push(int value){
if(top == SIZE-1)
printf("\nStack is Full!!! Insertion is not possible!!!");
else{
top++;
stack[top] = value;
printf("\nInsertion success!!!");
}
}
void pop(){
if(top == -1)
printf("\nStack is Empty!!! Deletion is not possible!!!");
else{
printf("\nDeleted : %d", stack[top]);
top--;
}
}
void display(){
if(top == -1)
printf("\nStack is Empty!!!");
else{
int i;
printf("\nStack elements are:\n");
for(i=top; i>=0; i--)
printf("%d\n",stack[i]);
}
}

APPLICATIONS OF STACKS
REVERSING A LIST USING STACK

A simple example of stack application is reversal of a given list. We can accomplish this stack by
pushing each element onto the stack as it is read. When the line is finished, elements are then
popped off the stack.

Suppose, the string of array is:

3
Data Structures using C Init - II

We can create stack of elements and logical representation PUSH operations of stack.

4
Data Structures using C Init - II

POP operations of stack are:

/* Implementation: The reverse of a string using a Stack */

#include<stdio.h>
#include<string.h>

#define MAX 20

int element;
int top = -1;
char stack_array[MAX];
void push(char element);
int isEmpty();
int isFull();
char pop();

void main()
{

5
Data Structures using C Init - II

char stack_string[30];
int count;
printf("Enter A String:\t");
scanf("%s", stack_string);
for(count = 0; count < strlen(stack_string); count++)
{
push(stack_string[count]);
}
for(count = 0; count < strlen(stack_string); count++)
{
stack_string[count] = pop();
}
printf("%s", stack_string);
printf("\n");
}

void push(char element)


{
if(isFull())
{
printf("\nStack Overflow\n");
}
else
{
top = top + 1;
stack_array[top] = element;
}
}

char pop()
{
if(isEmpty())
{
printf("\nStack Underflow\n");
return 1;
}
else
{
element = stack_array[top];
top = top - 1;
return element;
}
}

int isEmpty()
{
if(top == -1)
return 1;
else
return 0;
}

int isFull()
{
if(top == MAX-1)
return 1;

6
Data Structures using C Init - II

else
return 0;
}

POLISH NOTATIONS

The process of writing the operators of an expression either before their operands or after them
is called the Polish Notation. The main property of polish notation is that the order in which
operations are to be performed is ascertained by the position of the operators and operands in
the expression.

An expression is a collection of operators and operands that represents a specific value.

Operator is a symbol which performs a particular task like arithmetic operation or logical
operation or conditional operation etc.

Operands are the values on which the operators can perform the task. Here operand can be a
direct value or variable or address of memory location.

The complex arithmetic expressions can be converted into polish string using stacks which can
then be executed in two operands and an operator form. The notation refers to the complex
arithmetic expressions in three forms:

1. Prefix notation: if the operator symbols are placed before its operands, then the
expression in prefix notation.
2. Postfix notation: if the operator symbols are placed after its operands, then the
expression in postfix notation.
3. Infix notation: if the operator symbols are placed between its operands, then the
expression in infix notation.
Expression Representation

Infix Prefix Postfix

a+b +ab ab+

a+b*c +a*bc abc*+

(a + b) * (c - d) *+ab-cd ab+cd-*

INFIX TO POSTFIX CONVERSION


Algorithm for Postfix Conversion
1. Scan the Infix string from left to right.

2. Initialize an empty stack.

3. If the scanned element is an operand, add it to the Postfix string.

4. If the scanned element is an operator and if the stack is empty push the element to stack.

5. If the scanned element is an Operator and the stack is not empty, compare the precedence of
the element with the element on top of the stack.

7
Data Structures using C Init - II

6. If top Stack has higher precedence over the scanned element pop the stack else push the
scanned element to stack. Repeat this step until the stack is not empty and top Stack has
precedence over the element.
7. Repeat 4 and 5 steps till all the elements are scanned.

8. After all elements are scanned, we have to add any element that the stack may have to the
Postfix string.
9. If stack is not empty add top Stack to Postfix string and Pop the stack.

10.Repeat this step as long as stack is not empty.

EXAMPLE:

A+(B*C-(D/E-F)*G)*H

Stack Input Output

Empty A+(B*C-(D/E-F)*G)*H -
Empty +(B*C-(D/E-F)*G)*H A
+ (B*C-(D/E-F)*G)*H A
+( B*C-(D/E-F)*G)*H A
+( *C-(D/E-F)*G)*H AB
+(* C-(D/E-F)*G)*H AB
+(* -(D/E-F)*G)*H ABC
+(- (D/E-F)*G)*H ABC*
+(-( D/E-F)*G)*H ABC*
+(-( /E-F)*G)*H ABC*D
+(-(/ E-F)*G)*H ABC*D
+(-(/ -F)*G)*H ABC*DE
+(-(- F)*G)*H ABC*DE/
+(-(- F)*G)*H ABC*DE/
+(-(- )*G)*H ABC*DE/F
+(- *G)*H ABC*DE/F-
+(-* G)*H ABC*DE/F-
+(-* )*H ABC*DE/F-G
+ *H ABC*DE/F-G*-
+* H ABC*DE/F-G*-
+* End ABC*DE/F-G*-H
Empty End ABC*DE/F-G*-H*+

EVALUATION OF POSTFIX EXPRESSION

Evaluation rule of a postfix expression states:

While reading the expression from left to right, push the element into the stack if it is an operand;
pop the two operands from the stack, if the element is an operator (except NOT operator). In

8
Data Structures using C Init - II

case it is NOT an operator, pop one operand from the stack and then evaluate it (two operators
and an operand). Push back the results of the evaluation. Repeat it till the end of the stack.

Algorithm for evaluation of postfix expression

1. Scan the elements of the postfix string from left to right one by one.
a. If the element is an operand then push it on the stack.
b. If the element is an operator then pop two elements from the
stack and apply the operator to these two elements. Now, push the
result on the stack.
2. After all the elements have been scanned, pop the remaining element of
the stack and that is the value of the arithmetic postfix expression.

Example

Infix Expression: (3 + 4) * (2 / 2)

Postfix Expression: 34+22/*

Evaluation: 7

/* Evaluation of Postfix Expression */

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

void push(long int character);


long int postfix_evaluation();
int pop();
int isEmpty();

int top;
long int stack[50];
char postfix_expression[50];

int main()
{
long int evaluated_value;
top = -1;
printf("\nEnter an Expression in Postfix format:\t");
scanf("%[^\n]s", postfix_expression);
printf("\nExpression in Postfix Format: \t%s\n", postfix_expression);
evaluated_value = postfix_evaluation();
printf("\nEvaluation of Postfix Expression: \t%ld\n", evaluated_value);
return 0;
}

long int postfix_evaluation()


{
long int x, y, temp, value;
int count;
for(count = 0; count < strlen(postfix_expression); count++)
{
if(postfix_expression[count] <= '9' && postfix_expression[count] >=
'0')
{

9
Data Structures using C Init - II

push(postfix_expression[count] - '0');
}
else
{
x = pop();
y = pop();
switch(postfix_expression[count])
{
case '+': temp = y + x;
break;
case '-': temp = y - x;
break;
case '*': temp = y * x;
break;
case '/': temp = y / x;
break;
case '%': temp = y % x;
break;
case '^': temp = pow(y, x);
break;
default: printf("Invalid");
}
push(temp);
}
}
value = pop();
return value;
}

void push(long int character)


{
if(top > 50)
{
printf("Stack Overflow\n");
exit(1);
}
top = top + 1;
stack[top] = character;
}

int pop()
{
if(isEmpty())
{
printf("Stack is Empty\n");
exit(1);
}
return(stack[top--]);
}

int isEmpty()
{
if(top == -1)
{
return 1;
}

10
Data Structures using C Init - II

else
{
return 0;
}
}

ALGORITHM FOR EVALUATING INFIX TO PREFIX EXPRESSION


Step 1. Push “)” onto STACK, and add “(“ to end of the A
Step 2. Scan A from right to left and repeat step 3 to 6 for each element of A until the STACK
is empty
Step 3. If an operand is encountered add it to B
Step 4. If a right parenthesis is encountered push it onto STACK
Step 5. If an operator is encountered then:

a. Repeatedly pop from STACK and add to B each operator (on the top of
STACK) which has same or higher precedence than the operator.

b. Add operator to STACK


Step 6. If left parenthesis is encountered then

a. Repeatedly pop from the STACK and add to B (each operator on top of
stack until a left parenthesis is encountered)

b. b. Remove the left parenthesis


Step 7. Exit

Example

Expression = (A+B^C)*D+E^5

Step 1. Reverse the infix expression.


5^E+D*)C^B+A(

Step 2. Make Every '(' as ')' and every ')' as '('


5^E+D*(C^B+A)

Step 3. Convert expression to postfix form.

Expression Stack Output Comment

5^E+D*(C^B+A) Empty - Initial


^E+D*(C^B+A) Empty 5 Print
E+D*(C^B+A) ^ 5 Push
+D*(C^B+A) ^ 5E Push
D*(C^B+A) + 5E^ Pop And Push
*(C^B+A) + 5E^D Print

11
Data Structures using C Init - II

(C^B+A) +* 5E^D Push


C^B+A) +*( 5E^D Push
^B+A) +*( 5E^DC Print
B+A) +*(^ 5E^DC Push
+A) +*(^ 5E^DCB Print
A) +*(+ 5E^DCB^ Pop And Push
) +*(+ 5E^DCB^A Print
End +* 5E^DCB^A+ Pop Until '('
End Empty 5E^DCB^A+*+ Pop Every element

Step 4. Reverse the expression.


+*+A^BCD^E5

Result +*+A^BCD^E5

RECURSION
A function that calls itself is known as a recursive function. And, this technique is known as
recursion.
NATURAL NUMBERS

Algorithm for Multiplication of Natural Numbers

1. Give input to num;

2. If num!=1, then,

a. Repeat: num * mul(num - 1);

3. If not num!=1, then

4. Return num.

C function for Multiplication of Natural Numbers

#include <stdio.h>
int mul(int n);

int main()
{
int number, result;

printf("Enter a positive integer: ");


scanf("%d", &number);

12
Data Structures using C Init - II

result = mul(number);

printf("multiplication=%d", result);
return 0;
}
int mul(int num)
{
if (num!=1)
return num * mul(num-1); // mul() function calls itself
else
return num;
}

FACTORIAL FUNCTION

Algorithm for factorial function

FACTORIAL (Fact, N)
This algorithm use recursive approach to find factorial of N.
Step 1: Start
Step 2: Read: Take input N
Step 3: If N == 0 then Print: Fact = 1 and Exit
Step 4: Call FACTORIAL (Fact, N – 1)
Step 5: Set Fact = N*Fact
Step 6: Return

C program for factorial function

#include<stdio.h>
#include<conio.h>
void main( )
{
int num, factorial ;
clrscr();
printf ( "\nEnter any number " ) ;
scanf ( "%d", &num ) ;
factorial = fact ( num ) ;
printf ( "Factorial value = %d", factorial ) ;
getch();
}
fact ( int n )

13
Data Structures using C Init - II

if ( n == 0 )
return ( 1 ) ;
else
return(n * fact ( n - 1 ) );
}

GCD FUNCTION (GREATEST COMMON DIVISOR)

In mathematics, the greatest common divisor (gcd) of two or more integers, when at least one of
them is not zero, is the largest positive integer that divides the numbers without a remainder. For
example, the GCD of 8 and 12 is 4.

Algorithm to find GCD using Euclidean algorithm

Step1. Begin:

Step2. function gcd(a, b)

Step3. If (b = 0) then

a. return a

End if

Else

b. return gcd(b, a mod b);

End if

Step4. End function

Step5. End

C program to find GCD (HCF) of two numbers using recursion

#include <stdio.h>

int gcd(int a, int b);

int main()

{ int num1, num2, hcf;

printf("Enter any two numbers to find GCD: ");

scanf("%d%d", &num1, &num2);

hcf = gcd(num1, num2);

14
Data Structures using C Init - II

printf("GCD of %d and %d = %d\n", num1, num2, hcf);


return 0;
}

int gcd(int a, int b)


{
if(b == 0)
return a;
else
return gcd(b, a%b);
}

Properties of Recursive functions

The idea of recursion into two simple rules:

1. Each recursive call should be on a smaller instance of the same problem, that is, a
smaller subproblem.
2. The recursive calls must eventually reach a base case, which is solved without further
recursion.

Advantages and Disadvantages of Recursion


Advantages

 Reduce unnecessary calling of function.

 Through Recursion one can solve problems in easy way while its iterative solution is very
big and complex.
Disadvantages

 It is very difficult to debug and understand.

 In recursive we must have an if statement somewhere to force the function to return


without the recursive call being executed, otherwise the function will never return.

 Recursion takes a lot of stack space, usually not considerable when the program is small
and running on a PC.

 Recursion uses more processor time.

15
Data Structures using C Init - II

QUEUES
Queues is a kind of abstract data type where items are inserted one end (rear end) known
as enqueue operation and deteted from the other end(front end) known as dequeue operation.
This makes the queue a First-In-First-Out (FIFO) data structure.

Sequential (Array) Representation:

A queue data structure can be implemented using one dimensional array. But, queue
implemented using array can store only fixed number of data values.

Define a one dimensional array of specific size (QUEUE[SIZE]) and insert or delete the values
into that array by using FIFO (First In First Out) .

Steps to create an empty queue.

Step1. Create a one dimensional array with above defined SIZE (int queue[SIZE])
Step2. Define two integer variables 'front' and 'rear' and initialize both with '-1'. (int front = -
1, rear = -1)
Step3. Declare all the user defined functions (enQueue and deQueue) which are used in
queue implementation.
a. To insert a new value into the queue, increment 'rear' value by one and then
insert at that position.
b. To delete a value from the queue, then increment 'front' value by one and
then display the value at 'front' position as deleted element.

16
Data Structures using C Init - II

Implementation of Queue and their Operations


enQueue operation

In a queue data structure, enQueue() is a function used to insert a new element into the queue.
In a queue, the new element is always inserted at rear position.

Step1. Check whether queue is FULL. (rear == SIZE-1)


Step2. If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and
terminate the function.
Step3. If it is NOT FULL, then increment rear value by one (rear++) and
set queue[rear] = value.

deQueue operation

In a queue data structure, deQueue() is a function used to delete an element from the queue. In
a queue, the element is always deleted from front position.

Step1. Check whether queue is EMPTY. (front == rear)


Step2. If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not possible!!!" and
terminate the function.
Step3. If it is NOT EMPTY, then increment the front value by one (front ++). Then
display queue[front] as deleted element. Then check whether
both front and rear are equal (front == rear), if it TRUE, then set
both front and rear to '-1' (front = rear = -1).

/* Program to implement Queue using Array */

#include<stdio.h>
#include<conio.h>
#define SIZE 10

void enQueue(int);
void deQueue();
void display();

int queue[SIZE], front = -1, rear = -1;

void main()
{
int value, choice;
clrscr();
while(1){
printf("\n\n***** MENU *****\n");
printf("1. Insertion\n2. Deletion\n3. Display\n4. Exit");
printf("\nEnter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter the value to be insert: ");
scanf("%d",&value);
enQueue(value);
break;
case 2: deQueue();
break;
case 3: display();

17
Data Structures using C Init - II

break;
case 4: exit(0);
default: printf("\nWrong selection!!! Try again!!!");
}
}
}
void enQueue(int value){
if(rear == SIZE-1)
printf("\nQueue is Full!!! Insertion is not possible!!!");
else{
if(front == -1)
front = 0;
rear++;
queue[rear] = value;
printf("\nInsertion success!!!");
}
}
void deQueue(){
if(front == rear)
printf("\nQueue is Empty!!! Deletion is not possible!!!");
else{
printf("\nDeleted : %d", queue[front]);
front++;
if(front == rear)
front = rear = -1;
}
}
void display(){
if(rear == -1)
printf("\nQueue is Empty!!!");
else{
int i;
printf("\nQueue elements are:\n");
for(i=front; i<=rear; i++)
printf("%d\t",queue[i]);
}
}

CIRCULAR QUEUE

In a normal Queue Data Structure, we can insert elements until queue becomes full. But once if
queue becomes full, we cannot insert the next element until all the elements are deleted from the
queue. For example consider the queue below...

After inserting all the elements into the queue.

Now consider the following situation after deleting three elements from the queue...

18
Data Structures using C Init - II

This situation also says that Queue is Full and we cannot insert the new element because, 'rear'
is still at last position. In above situation, even though we have empty positions in the queue we
cannot make use of them to insert new element. This is the major problem in normal queue data
structure. To overcome this problem we use circular queue data structure.

A Circular Queue can be defined as follows...

Circular Queue is a linear data structure in which the operations are performed based on
FIFO (First In First Out) principle and the last position is connected back to the first
position to make a circle.

Graphical representation of a circular queue is as follows...

Implementation of Circular Queue


enQueue(value)

In a circular queue, enQueue() is a function which is used to insert an element into the circular
queue. In a circular queue, the new element is always inserted at rear position. The enQueue()
function takes one integer value as parameter and inserts that value into the circular queue. We
can use the following steps to insert an element into the circular queue...

Step1. Check whether queue is FULL. ((rear == SIZE-1 && front == 0) || (front == rear+1))

Step2. If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and
terminate the function.

Step3. If it is NOT FULL, then check rear == SIZE - 1 && front != 0 if it is TRUE, then
set rear = -1.

Step4. Increment rear value by one (rear++), set queue[rear] = value and check 'front == -
1' if it is TRUE, then set front = 0.

19
Data Structures using C Init - II

deQueue()

In a circular queue, deQueue() is a function used to delete an element from the circular queue. In
a circular queue, the element is always deleted from front position. The deQueue() function
doesn't take any value as parameter. We can use the following steps to delete an element from
the circular queue...

Step1. Check whether queue is EMPTY. (front == -1 && rear == -1)

Step2. If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not


possible!!!" and terminate the function.

Step3. If it is NOT EMPTY, then display queue[front] as deleted element and increment
the front value by one (front ++). Then check whether front == SIZE, if it
is TRUE, then set front = 0. Then check whether both front - 1 and rear are
equal (front -1 == rear), if it TRUE, then set both front and rear to '-1'
(front = rear = -1).

/* Program to implement Queue using Array */

#include<stdio.h>
#include<conio.h>
#define SIZE 5

void enQueue(int);
void deQueue();
void display();

int cQueue[SIZE], front = -1, rear = -1;

void main()
{
int choice, value;
clrscr();
while(1){
printf("\n****** MENU ******\n");
printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("\nEnter the value to be insert: ");
scanf("%d",&value);
enQueue(value);
break;
case 2: deQueue();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nPlease select the correct choice!!!\n");
}
}
}
void enQueue(int value)
{
if((front == 0 && rear == SIZE - 1) || (front == rear+1))

20
Data Structures using C Init - II

printf("\nCircular Queue is Full! Insertion not possible!!!\n");


else{
if(rear == SIZE-1 && front != 0)
rear = -1;
cQueue[++rear] = value;
printf("\nInsertion Success!!!\n");
if(front == -1)
front = 0;
}
}
void deQueue()
{
if(front == -1 && rear == -1)
printf("\nCircular Queue is Empty! Deletion is not possible!!!\n");
else{
printf("\nDeleted element : %d\n",cQueue[front++]);
if(front == SIZE)
front = 0;
if(front-1 == rear)
front = rear = -1;
}
}
void display()
{
if(front == -1)
printf("\nCircular Queue is Empty!!!\n");
else{
int i = front;
printf("\nCircular Queue Elements are : \n");
if(front <= rear){
while(i <= rear)
printf("%d\t",cQueue[i++]);
}
else{
while(i <= SIZE - 1)
printf("%d\t", cQueue[i++]);
i = 0;
while(i <= rear)
printf("%d\t",cQueue[i++]);
}
}
}

DOUBLE ENDED QUEUE (DEQUEUE)

Double Ended Queue is also a Queue data structure in which the insertion and deletion
operations are performed at both the ends (frontand rear). That means, we can insert at both
front and rear positions and can delete from both front and rear positions.

21
Data Structures using C Init - II

Double Ended Queue can be represented in TWO ways, those are as follows...

1. Input Restricted Double Ended Queue

2. Output Restricted Double Ended Queue

Input Restricted Double Ended Queue

In input restricted double ended queue, the insertion operation is performed at only one end and
deletion operation is performed at both the ends.

Output Restricted Double Ended Queue

In output restricted double ended queue, the deletion operation is performed at only one end and
insertion operation is performed at both the ends.

PRIORITY QUEUES

A priority queue is a collection of elements where each element is assigned a priority and the
order in which elements are deleted and processed is determined from the following rules:

 An element of higher priority is processed before any element of lower priority.

 Two elements with the same priority are processed according to the order in which they
are added to the queue.

An example of a priority queue can be a timesharing system; program of high priority are
processed first, and program with same priority form a standard queue.

In figure, show the way the priority queue may appear in memory using linear arrays INFO, PRN
and LINK.

22
Data Structures using C Init - II

The main property of the one way list representation of a priority queue is that the element in the
queue that should be processed first always appears at the beginning of one way list.
Accordingly, it is a very simple matter to delete and process an element from our priority queue.

23

You might also like