Practice Tasks (Linked List + Stacks+ Queues)
Practice Tasks (Linked List + Stacks+ Queues)
1. Write a program in C to create a singly linked list of n nodes and display it in reverse order.
Test Data :
Input the number of nodes : 3
Input data for node 1 : 5
Input data for node 2 : 6
Input data for node 3 : 7
Expected Output :
Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs
to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of
matched pairs of brackets: [], {},and ().
A matching pair of brackets is not balanced if the set of brackets it encloses are not matched. For
example, {[(])} is not balanced because the contents in between { and } are not balanced. The
pair of square brackets encloses a single, unbalanced opening bracket, (, and the pair of
parentheses encloses a single, unbalanced closing square bracket, ].
By this logic, we say a sequence of brackets is balanced if the following conditions are met:
5. Infix : An expression is called the Infix expression if the operator appears in between the
operands in the expression. Simply of the form (operand1 operator operand2).
Example : (A+B) * (C-D)
Prefix : An expression is called the prefix expression if the operator appears in the expression
before the operands. Simply of the form (operator operand1 operand2).
Example : *+AB-CD (Infix : (A+B) * (C-D) )
Given a Prefix expression, convert it into a Infix expression.
Computers usually does the computation in either prefix or postfix (usually postfix). But for
humans, its easier to understand an Infix expression rather than a prefix. Hence conversion is
need for human understanding.
Examples:
Input : Prefix : *+AB-CD
Output : Infix : ((A+B)*(C-D))
7. Write a program to reverse a stack using recursion. You are not allowed to use loop constructs
like while, for..etc, and you can only use the following ADT functions on Stack S:
isEmpty(S)
push(S)
pop(S)
Input : 7 4 10 20 2 5 9 1
Output : 1 2 4 5 7 9 10 20
9. Given a singly linked list of characters, write a function that returns true if the given list is a
palindrome, else false.
10. Given a linked list and two keys in it, swap nodes for two given keys. Nodes should be
swapped by changing links. Swapping data of nodes may be expensive in many situations
when data contains many fields.
It may be assumed that all keys in the linked list are distinct.
Examples:
Input: 10->15->12->13->20->14, x = 12, y = 20
Output: 10->15->20->13->12->14