Professional Documents
Culture Documents
AIM :
ALGORITHM:
Step 2- Declare and initialise the member function and variable create a class which consists
of add, delete, display and all private variables.
Check whether the stack is full .if it is full display stack is full otherwise push
operation increases top by one and writes pushed element to array;
If the stack is empty then it is underflow else delete the items from the b stack pop
operation checks that top is not equal to -1 and decreases top variable by 1
Case 3 - DISPLAY
Check if top is equal to -1 ,print element is empty or else display the content of
stack.
RESULT:
AIM:
ALGORITHM:
Step 2: If there is only one node in singly linked list then the deletion takes place.
Step 3: If there is no element in the list, then the new node is added by linking head pointer
to the node.
Step 5: In case of delete operation, check for the list is empty & then print the delete element
& return.
RESULT:
AIM:
ALGORITHM:
Step 3: For ch=1; ch=2; ch=3; ch=4;ch=5; Call Create, insert, delete, view and exit functions
respectively.
Step 9: Stop.
RESULT:
AIM:
ALGORITHM:
Step 3: For ch=1; ch=2; ch=3; ch=4; ch=5; Call Create, insert, delete, view and exit functions
respectively.
Step 9: Stop.
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<malloc.h>
//using namespace std;
struct Node
{
int data;
struct Node *next;
};
//insert a new node in an empty list
struct Node *insertInEmpty(struct Node *last, int new_data)
{
// if last is not null then list is not empty, so return
if (last != NULL)
return last;
// allocate memory for node
struct Node *temp = new Node;
// Assign the data.
temp -> data = new_data;
last = temp;
// Create the link.
last->next = last;
return last;
}
//insert new node at the beginning of the list
struct Node *insertAtBegin(struct Node *last, int new_data)
{
//if list is empty then add the node by calling insertInEmpty
if (last == NULL)
RESULT:
AIM:
ALGORITHM:
Step 2: If there is no element in the list, then the new node is added and the node becomes
head as well as top node.
Step 3: The stack is growable by attaching more nodes, the newly created node becomes
the top node and the link of top becomes head node.
Step 4: The above step is repeated by making new node as top and link is attached to
previously created node
Step 5: In case of delete operation, check for the list is empty & then print the delete element
& return.
RESULT:
AIM:
ALGORITHM:
Step 2 - Declare and initialise the member function and variable create a class which consists
of add, delete, display and all private variables.
Case 1- Insert in to the stack Check whether the stack is full .if it is full display stack is full
otherwise push operation increases top by one and writes pushed element to array;
Case 2- Delete from the stack If the stack is empty then it is underflow else delete the items
from the b stack pop operation checks that top is not equal to -1 and decreases top
variable by 1
Case 3 –Display, Check if top is equal to -1, print element is empty or else display the content
of stack.
RESULT:
AIM:
ALGORITHM:
B) If the scanned character is an operator and if the stack is empty Push the character to
stack.
C) If the scanned character is an Operand and the stack is not empty, compare the
precedence of the character with the element on top of the stack (topstack).
D) If top stack has higher precedence over the scanned character Pop the stack else push
the scanned character to stack. Repeat this step as long as stack is not empty and
topstack has precedence over the character. Repeat this step till all the characters are
scanned.
5. (After all characters are scanned, we have to add any character that the stack may have to
the Postfix string.) If stack is not empty add topstack to Postfixstring and pop the
stack.Repeat this step as long as stack is not empty.
8. STOP
RESULT:
AIM:
ALGORITHM:
B) If the scanned character is an operator and if the stack is empty Push the character to
stack.
C) If the scanned character is an Operand and the stack is not empty, compare the
precedence of the character with the element on top of the stack (topstack).
D) If top stack has higher precedence over the scanned character Pop the stack else
Repeat this step as long as stack is not empty and topstack has precedence over the
character.
5. (After all characters are scanned, we have to add any character that the stack may have to
the Postfix string.) If stack is not empty add topstack to Postfixstring and Pop the stack.
Repeat this step as long as stack is not empty.
RESULT:
AIM:
ALGORITHM:
Step 2 - Declare and initialise the member function and variable create a class which consists
of add, delete, display and all private variables.
Check whether the queue is full. If queue is full display queue is full otherwise
increment rear.
Check whether the queue is full. If queue is EMPTY OR not, if queue is empty.
Case 3 -DISPLAY
Check if front is equal to -1, print element is empty or else display the content of
queue.
RESULT:
AIM:
ALGORITHM:
Step 4: Inqueue
c)mark it rear
d)return
RESULT:
AIM:
ALGORITHM:
Step 4: Inqueue
c) mark it rear
d) return
RESULT:
AIM:
ALGORITHM:
Step 4: For preorder traversal process root, left & right subtree.
RESULT:
AIM:
ALGORITHM:
Step 4: For preorder traversal process root, left & right subtree.
RESULT:
AIM:
ALGORITHM:
Step 2:
Start from the leftmost element of arr[] and one by one compare x with each clement of
arr[]
Else If x greater than the mid element, then x can only lie in right half subarray after
the middle element So we recur for right half.
Step 3: Prompt the user to select between linear and binary search.
Step 4: End the program
RESULT:
SORTING- SELECTION SORT, QUICK SORT, HEAP SORT AND MERGE SORT
AIM:
To write a C++ program on Sorting types – Selection Sort, Quick Sort, Heap Sort and
Merge Sort.
ALGORITHM:
In every iteration of selection sort, the minimum element considering ascending order)
from the unsorted subarray is picked and moved to the sorted subarray. Repeatedly
finding the minimum element (considering ascending order) from unsorted part and
putting it at the beginning
Select an element x of array as pivot, put x at its correct position in sorted array and
put all smaller elements smaller than before x, and put all greater elements (greater
than x) after x.
Using binary heap ie., parent node is stored at index I, the left child can be calculated
by 2*I + 1 and right child by 2*I+ 2 assuming the indexing starts at 0).The largest item
is stored at the root of the heap Replace it with the last item of the heap followed by
reducing the size of heap by 1
Divide the input array into two halves, cal and then merges the two sorted halves
AIM:
ALGORITHM:
Step 2: n=1
Step 3: ia=ib=ic=ja=jb=jc=1
Step 5: end.
RESULT:
AIM:
ALGORITHM:
Step 4: Traverse array B[] and do following for every element B[I] sum[I]=sum[I]+B[I]
Step 7: Traverse array A[] and do following for every element A[i]
RESULT:
AIM:
ALGORITHM:
Step 1: Start
U:pop s;
Visited[u] := true;
Push s,w;
End If.
End While.
Step7: Stop.
RESULT:
AIM:
ALGORITHM:
Step 1: start
Step 5: Visit the unvisited adjacent nodes and keep them in queue for traversing to their
adjacent nodes.
Step 6: Take nodes from queue one by one and repeat step 4 & 5 until queue is empty.
Step 7: Stop.
RESULT: