0% found this document useful (0 votes)
15 views63 pages

Updated Ds - Unit II

Unit II of the Data Structures course covers key concepts including the introduction to data structures, abstract data types (ADT), and the implementation of stacks and queues using arrays. It discusses stack operations, applications, and algorithms for converting infix expressions to postfix notation, as well as evaluating postfix expressions. The document provides examples and C programming implementations for stack operations and expression conversions.

Uploaded by

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

Updated Ds - Unit II

Unit II of the Data Structures course covers key concepts including the introduction to data structures, abstract data types (ADT), and the implementation of stacks and queues using arrays. It discusses stack operations, applications, and algorithms for converting infix expressions to postfix notation, as well as evaluating postfix expressions. The document provides examples and C programming implementations for stack operations and expression conversions.

Uploaded by

topgameryt997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Data Structures

( 9EC01)

UNIT - II
Topics to be covered in Unit-2:
Introduction to Data Structures
Abstract data type (ADT)
Stacks, Queues and Circular Queues and their
implementation with arrays
Stack Applications:
Infix to Post fix conversion
Postfix expression evaluation.
Applications of Queues
Introduction to Data Structures:
Data can be represented in the form of binary digits in memory.
A binary digit can be stored using the basic unit of data called bit.
A bit can represent either a zero or a one.

 Data means value or set of values or Data is a collection of raw


facts.

 Data structure is a way of storing and organizing data in an


efficient manner.

 Any data structure is designed to organize data to suit a


specific purpose so that it can be accessed and worked in
appropriate ways both effectively and efficiently.
 The main objective of the data structure is to store and
retrieve the data in effectively and efficiently.

 Mathematically, a data structure D is a triplet, that is,


D=(d, f, a) where
D= data structure
d= a set of variables (data objects)
f= a set of functions
a= set of rules to implement the functions.
Classification of Data Structures
 Several data structures are available in the computer science and
used based on their applications.
 Data structures are classified into different types.

Type

Linear Data Non Linear Data


Structures Structures

Arrays Linked Queue Trees Graphs


Stac
list k s
 Linear Data Structures: A data structure is said to be linear if its
elements form a sequence or a linear list.

 Non-linear Data Structures: A data structure is said to be non linear


if its elements are not in a sequence. The elements in the data
structure are not arranged in a linear manner; rather it has a
branched structure.
Abstract Data Type (ADT)
Abstract Data Type is a declaration of data ,declaration of
operations but no implementation details.

That is an Abstract Data Type (ADT) defines data together with the
operations.

ADT is specified independently of any particular implementation.

ADT depicts the basic nature or concept of the data structure rather
than the implementation details of the data.

A stack or a queue is an example of an ADT.

Both stacks and queues can be implemented using an array or using


a linked list.
Stack ADT Example

struct stack
{
int top, size;
};
void push();
void pop();
void display();
Stack
A stack is a Last In First Out (LIFO) data structure in which all
insertions and deletions are takes place at one end, called the top.

Stack maintains a variable called top, which keeps track of the top most
element in the stack.

Any insertions or deletions should be based upon the value of top.

In the stack, the elements are removed in the reverse order of that in
which they were added to the stack that is last element inserted is to be
deleted first.
Basic Stack Operations:
push/insert : To insert an item into stack
pop/delete : To delete an item from stack
traverse/display : To display an items
isFull : To know whether the stack is full or not
isEmpty : To know whether the stack is empty or not
A stack of cups

A stack of coins
Example 1:
When the elements are inserted in the order as A,B,C,D then the size
of the stack is 4 and the top most element in the stack is D.
When deletion operation is performed on stack continuously then the
order in which the elements are deleted is D,C,B,A.

D to
C to C p
B to B p B
A to A p A
p A

C to
p B to
B
p
A A A top
Example 2: Here Stack Size is
4
3 3 3
2 2 2
1 1 TOP-> 1 20
0 TOP-> 0 10 0 10

TOP = -1 Push 10 Push 20


(Empty stack)

TOP-> 3 40 TOP-> 3 40
3
TOP-> 2 2 30 2 30
30
1 20 1 20
1 20
0 10 0 10
0 10
Push 40 Push 50
Push 30
(Overflow)
3 3
TOP->2 30 2
1 20 TOP-> 1 20
0 10 0 10
pop pop

3 3
2
2
1 1
TOP-> 0 10 0
pop (TOP = -1)
pop underflow
Example:3
Example 4:
Implementing Stack using Array

A stack can be implemented either using an array or a linked list.

Procedure:

Initialize the stack by assigning -1 to the top variable to indicate that the
array based stack is empty.

A top is an integer value, which contains the array index for the top of
the stack.

Each time data is pushed or popped, top is incremented or decremented


accordingly, to keep track of the current top of the stack.

Stacks implemented as arrays are useful if a fixed amount of data is to


be used.
Algorithm for inserting an element into the stack
Algorithm :
push()
1. if top=size-1 then
1. print “stack is
full”
2. else
1. read item
2. top=top+1
3. stack[top]=item
3. endif
4. stop
The first step of this algorithm checks for an overflow condition.

Overflow means inserting an item into a stack which is full.

If the top value reaches to maximum size of the stack then items cannot
be inserted into the stack i.e. stack is full.

Otherwise top is incremented by one and item is inserted into the stack.
Algorithm for deleting an element from the stack
Algorithm pop()

1. if top = -1 then
print “stack is empty”
2. else
1. item = stack[top]
2. top=top-1
3.endif
4.stop

The first step of this algorithm checks for underflow


condition.

If the top value is -1 then stack is known as underflow or


empty.

Take out the element from the location where the top is
pointing and store it in the variable then decrement top by
one.
Algorithm for displaying an elements of the stack
Algorithm:
display()
1. if top = -1
1.print “stack empty”
2. else
1. for(i = top; i >= 0;i--)
1.print “stack[i]”
3.endif
4. stop

If the top value is -1 then the stack is empty.

If stack is not empty, assign top value to variable i, display


the item which is pointed at stack[i] and decrement the top
value by one and repeat this until top becomes zero.
/*1.Write a C program that implement stack and its operation by using the arrays.*/
#include<stdio.h> #include<stdlib.h> #define SIZE 4
void push(); void pop(); void display();

int isFull(); int isEmpty();


int choice,top=-1,stack[SIZE],item;
void main()
{
while(1) {
printf(" *** MENU ***\n 1. PUSH\n 2. POP\n 3.TRAVERSE\\DISPLAY\n 4.isFull\n
5.isEmpty\n 6.EXIT\n");
printf("enter your choice from menu:");
scanf("%d",&choice);
switch(choice) {
case 1 : push();
break;
case 2 : pop();
break;
case 3 : display();
break;
case 4 : isFull();
break;
case 5 : isEmpty();
break;
case 6 : exit(0);
default : printf("wrong choice\n");
void push() {
if(top==SIZE-1)
printf("*** stack overflow(full) ***\n");
else
{
printf("enter the item to be pushed into the stack:");
scanf("%d",&item);
top++;
stack[top]=item;
}
}//push

void pop() {
if(top==-1)
printf("*** stack is empty ***\n");
else
{
item=stack[top];
top--;
printf("the deleted item from stack is %d\n",item);
}
}//pop
int isEmpty(){
void display()
if(top==-1)
{
int i; printf("Stack is
empty\n");
if(top==-1)
else
printf("**** stack underflow****");
else printf("Stack is not
empty\n");
{
return 0;
printf("*** stack display ***\n");
for(i=top;i>=0;i--) }
{
if(i==top) int isFull()
printf("%d at {
%d ->top\n",stack[i],i); if(top==SIZE-1)
else
printf("Stack is full\
printf("%d at n");
%d\n",stack[i],i);
} else
} printf("Stack is not
full\n");
}
return 0;
}
Applications of Stack

The LIFO structure of the stack provides many applications of stack.


Applications:
1. Reversing an array of elements.
2. Converting an infix expression into RPN (Reverse Polish
Notation).
3. Evaluating a postfix or RPN expression.
Types of expressions
Arithmetic expressions can be represented in three ways:

Infix notation:The operator/operation is in between the two operands.


Examples: A+B
2+3

Prefix (Polish notation):The operator precedes the operands.


Examples: +AB
+23

Postfix (Reverse Polish Notation): The operator follows the operands.


Examples: AB+ 23+
Notations – Conversions
Consider the infix expression: 2 + 3 * (5 – 7) /
9
Let us insert implicit parentheses
(2 + ((3 * (5 – 7)) / 9))

Transfer the operators to the beginning of parentheses


(+ 2 (/ (* 3 (– 5 7)) 9))
Remove the parentheses: + 2 / * 3 – 5 7 9
This is the equivalent prefix expression.

Transfer the operators to the end of parentheses


(2 ((3 (5 7 –) *) 9 /) +)
Remove the parentheses: 2 3 5 7 – * 9 / +
This is the equivalent postfix expression.
Examples
Infix Prefix Postfix
Expression Expression Expression

2+3 +2 3 2 3 +

2+3*5 + 2 *3 5 2 3 5 * +

(2 + 3) * 5 * + 2 3 5 2 3 + 5 *

– * 2 3 + 5 2 3 * 5 9 +
2 * 3 – (5 + 9)
9 –
Infix to Postfix (RPN) Conversion
Algorithm to convert infix expression to RPN:
1. Initialize an empty stack.
2. Repeat the following until the end of the infix expression is reached.
1. Get next input token (constant, variable, arithmetic operator, left
parenthesis, right parenthesis) in the infix expression.
2. If the token is
1. A left parenthesis: Push it onto the stack.
2. A right parenthesis:
1. Pop and display stack elements until a left parenthesis is on the
top of the stack.
2. Pop the left parenthesis also, but do not display it.
3. An operator:
1. While the stack is nonempty and token has lower or equal
priority than stack top element, pop and display.
2. Push token onto the stack.
4. An operand: Display it.
3. When the end of the infix expression is reached, pop and display stack
items until the stack is empty.
An Example: 7-(2*3+5)*(8-4/2)  723*5+842/-*-
Remaining Infix String Stack Postfix String
7-(2*3+5)*(8-4/2) empty null
-(2*3+5)*(8-4/2) empty 7
(2*3+5)*(8-4/2) - 7
2*3+5)*(8-4/2) -( 7
*3+5)*(8-4/2) -( 72
3+5)*(8-4/2) -(* 72
+5)*(8-4/2) -(* 723
5)*(8-4/2) -(+ 723*
)*(8-4/2) -(+ 723*5
*(8-4/2) - 723*5+
(8-4/2) -* 723*5+
8-4/2) -*( 723*5+
-4/2) -*( 723*5+8
4/2) -*(- 723*5+8
/2) -*(- 723*5+84
2) -*(-/ 723*5+84
) -*(-/ 723*5+842
null empty 723*5+842/-*-
/*3i).Write a C program that uses stack operations to perform convertion of infix expression
into postfix expression.*/
#include<stdio.h> #include<ctype.h> #include<string.h> static char str[30]; int
top=-1;
int push(char); int pop(); int priority(char);
void main() {
char in[30],post[30],ch; int i,j,l; printf("\n Enter the string(Infix Expression): ");
scanf(“%s”,in); l=strlen(in); printf("\n The length of the given string is: %d\
n",l);
for(i=0,j=0;i<l;i++) {
if(isalpha(in[i]) || isdigit(in[i]))
post[j++]=in[i];
else {
if(in[i]=='(')
push(in[i]);
else
if(in[i]==')') {
while((ch=pop())!='(')
post[j++]=ch;
}
else {
while(priority(in[i])<=priority(str[top]))
post[j++]=pop();
push(in[i]);
}
}
while(top!=-1)
post[j++]=pop();
post[j]='\0';
printf("\nEquivalent infix to postfix is:%s ",post);
}//main
int push(char c) {
str[++top]=c;
return 0;
int priority (char c) { }//push
switch(c) {
case '+':
case '-': return int pop(){
1; return (str[top--]);
case '*': }//pop
case '/': return
2;
case '^': return
3;
}//switch
return 0;
}//priority
Evaluation of Postfix (RPN) Expression
Algorithm to evaluate Postfix Expression:
1. Initialize an empty stack.
2. Do
1. Get next token (constant, arithmetic operator) in RPN
expression.
2. If token is an operand, push it on the stack.
3. If token is an operator do the following:
1. Pop top two values from the stack. (If the stack does not
contain two items, report error.)
2. Apply operator token to these two values.
3. Push the resulting value onto the stack.
3. Until the end of the expression is encountered.
4. The value of the expression is on the top of the stack (and stack
should contain only this value).
Evaluate the postfix expression: 5,6,2,+,*,12,4,/,-
Remaining postfix String Symbol Scanned Stack
5 6 2 + * 12 4 / - no symbol empty
6 2 + * 12 4 / - 5 5
2 + * 12 4 / - 6 5
6+ * 12 4 / - 2 5 6 2
* 12 4 / - + 5 8
12 4 / - * 40
4 / - 12 40 12
/ - 4 40 12 4
- / 40 3
null - 37
/*3ii).Write a C program that uses Stack operations to perform the evaluation of
the postfix expression*/
#include<stdio.h>
#include<math.h>
#include<string.h>
void main() {
char postfix[30],t[30];
int stack[10],top=-1,len,i,j,op2,op1,n;
printf("\n\n\nEnter the postfix:");
scanf(“[^\n]s”,postfix);
len=strlen(postfix);
postfix[len]=‘#’; //Assume # as the last value of postfix expression
for(i=0;postfix[i]!=‘#’;i++)
{
j=0;
if(postfix[i]==‘ ‘)
continue;
if(postfix[i]=='+'||postfix[i]=='-'||postfix[i]=='*'||postfix[i]=='/'||postfix[i]=='^')
{
op2=stack[top--];
op1=stack[top--];
switch(postfix[i]) {
case '+': stack[++top]=op1+op2;
break;
case '-': stack[++top]=op1-op2;
break;
case '*': stack[++top]=op1*op2;
break;
case '/': stack[++top]=op1/op2;
break;
case '^': stack[++top]=pow(op1,op2);
break;
}//end of switch
}//end of if
else {
while(postfix[i]!=’ ‘) {
t[j++]=postfix[i++];
}
t[j]='\0';
n=atoi(t);
stack[++top]=n;
}
}//end of for
printf("\n\n\nResult=%d\n",stack[top]);
}//end of main
Queues
A queue is a First In First Out (FIFO) data structure in which
elements are accessed from two different ends called Front and
Rear. The elements are inserted into a queue through the Rear end
and are removed from the Front end.

A queue maintains two variables called Front and Rear. Front


refers to the first position of the queue and Rear refers to the last
position of the queue.

In the Queue, the elements are removed in the order of that in
which they were added to the queue, that is first element inserted is
to be deleted first.
Basic Queue Operations:

Insertion: To add a new item to the rear end of the queue.


The rear end always points to the recently added element.

Deletion: To delete the item from front end of the queue.


The front end always points to the recently removed element.

Display: To display the items of queue.


Bus Stop Queue

Bus
Stop

front rear rear rear rear


rear
Bus Stop Queue

Bus
Stop

front rear rear


rear
Bus Stop Queue

Bus
Stop

front rear
rear
Bus Stop Queue

Bus
Stop

front rear
rear
front rear
New people must enter the queue at the
rear.

front
rear
People should leave the queue
from the front end.

rear
front
Types of Queues
 Linear Queue
 Circular Queue
 Double Ended Queue
 Priority Queue

Linear Queue: It is the one in which the insertions are takes place at
rear end and deletions are takes place at front end.

Circular Queue: It is the one in which the insertion of a new element


is done at the very first location of the queue if the last location of the
queue is full. i.e. circular queue is one in which the first element
comes just after the last element.
 Double Ended Queue: It is a homogeneous list of elements in which
insertion and deletion operations are performed from both the ends.
They are also called as deque.

There are two types of deques:


Input-restricted deques and Output-restricted deques

 Priority Queue: In priority queues, the items added to the queue have a
priority associated with them which determines the order in which
they exit the queue. Items with highest priority are removed first.
Working of a linear queue:
i) Initially front=rear= -1. It indicates queue is empty.
0 1 2 3 4

front=rear= -1

ii) Add 10 iii) Add 20


0 1 2 3 4 0 1 2 3 4
10 10 20

front rear front rear

iv) Add 30 v) Add 40


0 1 2 3 4 0 1 2 3 4
10 20 30 10 20 30 40

front rear front rear


vi) Add 50 vii) Add 60 (overflow)

0 1 2 3 4 0 1 2 3 4
10 20 30 40 50 10 20 30 40 50

front rear front rear

viii) delete (10 is removed) ix) delete (20 is removed)


0 1 2 3 4 0 1 2 3 4
20 30 40 50 30 40 50

front rear front rear


x) delete (30 is removed) xi) delete (40 is removed)

0 1 2 3 4 0 1 2 3 4
40 50 50

front front rear


rear

xii) delete (50 is removed) xii) delete (underflow)


0 1 2 3 4 0 1 2 3 4

front=rear= -1 front=rear= -1
Implementing Queue using Array

A queue can be implemented either using an array or a linked list.

Procedure:

Initialize the queue by assigning -1 to the front & rear variables to


indicate that the array based queue is empty.

Each time data is inserted rear value is incremented by one and


when data is deleted front value is also incremented by one.
Algorithm for inserting an element into the queue

Algorithm :insert() Explanation:


1. if rear = size-1 then This procedure adds an item to
the queue.
1. print “queue is
full”
First it checks for an overflow
2. exit condition.
2. else
1. if rear = -1 and front = If the rear value reaches of the
-1 queue then elements cannot be
inserted into the queue. ie. Queue
1. front = 0 is full.
2. endif
2. rear = rear + 1 Whenever element is inserted into
3. queue[rear] = item the queue, rear is increment by
one and place the element in the
3. endif location where rear is pointing.
4. stop
Algorithm for deleting an element from the queue

Explanation:
This procedure deletes an element from
Algorithm delete() the queue.
1. if front = -1 then
1. print “queue is The first step of this algorithm checks
empty” for underflow condition.
2. exit
If the front value is -1 then queue is
2. else empty.
1. item =
queue[front] Take out the element from the location
2. front = front + where, the front is pointing and store it
1 in the variable, then increment front by
3. endif one.

4. stop
Algorithm for displaying an elements from the queue
Algorithm display()
1. if front = -1 then
1. print “queue is
empty”
2. exit
2. else
1. for(i = front; i <=
rear; i++)
1. print
“queue[i]”
3. endif
4. stop
If the front value is -1 then the queue is empty.

If queue is not empty, display the item which is pointed at


queue[front] and increment the front value by one and
repeat this until front <= rear.
/*2. Write a C program that implement Queue and its operations using the arrays*/
#include<stdio.h> #include<stdlib.h> #define size 4
void insertion(); void deletion(); void display();
int front=-1,rear=-1,item,choice,queue[size];
void main() {
while(1) {
printf("\n*** MENU ***\n 1. INSERTION\n 2. DELETION\n 3.TRAVERSE\n 4. EXIT\
n");
printf("enter your choice:");
scanf("%d",&choice);
switch(choice) {
case 1 : insertion();
break;
case 2 : deletion();
break;
case 3 : display();
break;
case 4 : exit(0);
default : printf("*** wrong choice ***\n");
}//switch
}//while
}//main
void insertion() {
if(rear==size-1)
printf("*** queue is full ***\n");
else {
printf("enter item into queue:");
void display() {
scanf("%d",&item);
int i;
rear++;
if(front = = -1)
queue[rear] = item;
printf("*** queue is empty ***\
if(front = = -1)
n");
front++;
else {
}//else
printf("\n elements in queue:- ");
}//insertion
for(i=front;i<=rear;i++)
printf("%d ",queue[i]);
void deletion() {
}//else
if(front = = -1)
}//display
printf("*** queue is empty ***\n");
else
{
item = queue[front];
front++;
printf("the deleted item from queue is %d\
n",item);
}//else
}//deletion
Circular Queue:

It is the one in which the insertion of a new element is done at the


very first location of the queue if the last location of the queue is
full. i.e. circular queue is one in which the first element comes
just after the last element.

A circular queue overcomes the problem of unutilized space in


linear queues implemented as arrays.

A circular queue also have a Front and Rear to keep the track of
elements to be deleted and inserted and therefore to maintain the
unique characteristic of the queue.

Examples:
Print spooler of operating system
Revolvers bullet cylinder
Traffic light sequence
Bottle caping system in cold drink factory
Circular Queue with size 5 After adding 5, 10, 20

After adding 30, 40


After deleting 5

Now Q[0] will be available in


the queue for another insertion
Insertion Algorithm: Deletion Algorithm:

1. if front == (rear+1)%size 1. if front = = -1


1. Queue is Overflow 1. Queue Underflow
2. if front == -1 2. delete item at cq[front]
1. front = rear = 0 3. if front = = rear
3. else 1. front = -1;
4. if rear == size - 1 2. rear = -1;
1. rear =0 4. else
5. else 5. if front = = SIZE-1
1. rear = rear + 1
1. front = 0;
6. read item; 6. else
7. cq[rear] = item 1. front = front+1;
Algorithm to Display :

1. front_pos = front, rear_pos = rear;


2. if front == -1
1. Queue is empty
3. if front_pos <= rear_pos
1. while front_pos <= rear_pos
1. print cq[front_pos]
2. front_pos++;
4. else
1. while front_pos <= SIZE-1
1. print cq[front_pos]
2. front_pos++;
2. front_pos = 0;
3. while front_pos <= rear_pos
1. print cq[front_pos]
• front_pos++;
/* Program for circular queue using array*/
# include<stdio.h> # include<stdlib.h> # define SIZE 4
void insert(); void del();
void display();
int cq[SIZE]; int front = -1;
int rear = -1;
int main() {
int choice;
while(1) {
printf("1.Insert\n 2.Delete\n 3.Display\n 4.Quit\
n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice) {
case 1 : insert();
break;
case 2 : del();
break;
case 3: display();
break;
case 4: exit(0);
void insert() {
int item;
if(front == (rear+1)%SIZE) {
printf("Queue Overflow \n");
return;
}
if (front == -1) { /*If queue is empty */
front = 0;
rear = 0;
}
else
if(rear == SIZE-1)/*rear is at last position of queue */
rear = 0;
else
rear = rear+1;
printf("Input the element for insertion in
queue : ");
scanf("%d", &item);
cq[rear] = item ;
}/*End of insert()*/
void del()
{
if (front == -1) {
printf("Queue Underflow\n");
return;
}
printf("Element deleted from queue is: %d\
n",cq[front]);
if(front == rear) { /* queue has only one element */
front = -1;
rear = -1;
}
else
if(front == SIZE-1)
front = 0;
else
front = front+1;
}/*End of del() */
else
void display()
{
{
while(front_pos <= SIZE-1)
int front_pos = front,rear_pos =
{
rear;
printf("%d
if(front == -1)
",cq[front_pos]);
{
front_pos++;
printf("Queue is empty\
}
n");
front_pos = 0;
return;
while(front_pos <= rear_pos)
}
{
printf("%d
printf("Queue elements :\n");
",cq[front_pos]);
front_pos++;
if( front_pos <= rear_pos )
}
while(front_pos <= rear_pos)
}/*End of else */
{
printf("%d
printf("\n");
",cq[front_pos]);
front_pos++;
}/*End of display() */
}
Applications of Queue

There are several applications of queues in computer science.

1. Implements the various aspects of an operating systems.


2. CPU scheduling in Multiprogramming environment- single CPU has
to serve more than one program simultaneously.
3. Round Robin CPU scheduling algorithm.
4. Operating System maintains a queue of processes that are ready to
process or that are waiting for particular event to occur.
5. Printer maintains a queue.
6. Call waiting when you are attending other call
7. A file server in a computer network handles file access request from
many clients throughout the network. Servers have a limited capacity
to service request from clients, when that capacity is exceeded, client
requests wait in queues.
Convert infix to postfix expression

1. (A-B)*(D/E)
2. (A+B^D)/(E-F)+G
3. A*(B+D)/E-F*(G+H/K)
4. ((A+B)*D)^(E-F)
5. (A-B)/((D+E)*F)
6. ((A+B)/D)^((E-F)*G)
7. 12/(7-3)+2*(1+5)
8. 5+3^2-8/4*3+6
9. 6+2^3+9/3-4*5
10. 6+2^3^2-4*5
Evaluate the postfix expression

1. 5,3,+,2,*,6,9,7,-,/,-
2. 3,5,+,6,4,-,*,4,1,-,2,^,+
3. 3,1,+,2,^,7,4,1,-,2,*,+,5.-,-

You might also like