Competitive Coding Lab CS426
Competitive Coding Lab CS426
LAB MANUAL
Session 2024-2025
Branch : - CSE
Year : - 4th
Semester : - 7th
MISSION
To offer diverse academic programs at undergraduate, postgraduate, and doctorate levels that are in line with the current
trends in Computer Science and Engineering.
To provide the state of the art infrastructure for teaching, learning and research.
To facilitate collaborations with other universities, industry and research labs.
To produce graduates who have strong foundation of knowledge and skills in the field of computer science
PEO1 and engineering.
PEO2
To produce graduates who are employable in industries/public sector/research organizations or work as an
entrepreneur.
PEO3
To produce graduates who can provide solutions to challenging problems in their profession by applying
computer engineering theory and practices.
PEO4
To produce graduates who can provide leadership and are effective in multidisciplinary environment.
Reference Books:-
1. S.K.Srivastava “Data Structure Through C”
2. R.B.Patel “Data Structure and Algorithms”
3. Yogesh Sachdeva “Data Structure Using C”
4. A.K. Sharma “Data Structure Using C”
5. A.A. Puntambekar “Data Structure and Algorithms”
OBJECTIVE
#include<stdio.h>
void main()
{
int a[4],i,pos,data;
printf("Enter the number");
for(i=0;i<3;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the position");
scanf("%d",&pos);
printf("Enter the Data");
scanf("%d",&data);
for(i=2;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=data;
printf("The Final Array is\n");
for(i=0;i<4;i++)
{
printf("%d\t",a[i]);
}
}
OBJECTIVE
#include<stdio.h>
void main()
{
int a[5],i,pos,data;
printf("Enter the number");
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the position");
scanf("%d",&pos);
for(i=pos;i<4;i++)
{
a[i]=a[i+1];
}
printf("The Final Array is\n");
for(i=0;i<3;i++)
{
printf("%d\t",a[i]);
}
}
Sorting:-
Sorting is any process of arranging items according to a certain sequence or in different sets,
and therefore, it has two common, yet distinct meanings:
Ordering: arranging items of the same kind, class or nature, in some ordered sequence,
Categorizing: grouping and labeling items with similar properties together (by sorts).
Bubble Sort:-
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that works
by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items
and swapping them if they are in the wrong order. The pass through the list is repeated until
no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from
the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to
operate on elements, it is a comparison sort. Although the algorithm is simple, most of the
other sorting algorithms are more efficient for large lists.
Selection Sort:-
Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O (n2)
time complexity, making it inefficient on large lists, and generally performs worse than the
similar insertion sort. Selection sort is noted for its simplicity, and it has performance
advantages over more complicated algorithms in certain situations, particularly where
auxiliary memory is limited.
The algorithm divides the input list into two parts: the sublist of items already sorted, which
is built up from left to right at the front (left) of the list, and the sublist of items remaining to
be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted
sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest,
depending on sorting order) element in the unsorted sublist, exchanging it with the leftmost
unsorted element (putting it in sorted order), and moving the sublist boundaries one element
to the right.
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item
at a time. It is much less efficient on large lists than more advanced algorithms such as quick
sort, heap sort, or merge sort. However, insertion sort provides several advantages: Simple
implementation
Efficient for (quite) small data sets
Adaptive (i.e., efficient) for data sets that are already substantially sorted: the time
complexity is O (n + d), where d is the number of inversions.
More efficient in practice than most other simple quadratic (i.e., O(n2)) algorithms such as
selection sort or bubble sort; the best case (nearly sorted input) is O(n) stable; i.e., does not
change the relative order of elements with equal keys in-place; i.e., only requires a constant
amount O(1) of additional memory space; i.e., can sort a list as it receives it When humans
manually sort something (for example, a deck of playing cards), most use a method that is
similar to insertion sort.
Quick Sort:-
Quick sort, or partition-exchange sort, is a sorting algorithm developed by Tony Hoare that,
on average, makes O(nlogn) comparisons to sort n items. In the worst case, it makes O (n2)
comparisons, though this behavior is rare. Quick sort is often faster in practice than other
O(nlogn) algorithms. Additionally, quick sort sequential and localized memory references
work well with a cache. Quick sort is a comparison sort and, in efficient implementations, is
not a stable sort. Quick sort can be implemented with an in-place partitioning, so the entire
sort can be done with only O(logn) additional space used by the stack during the recursion.
Merge Sort:-
In computer science, merge sort (also commonly spelled merge sort) is an O (n log n)
comparison-based sorting algorithm. Most implementations produce a stable sort, which
means that the implementation preserves the input order of equal elements in the sorted
output. Merge sort is a divide and conquer algorithm that was invented by John von
Neumann in 1945.
OBJECTIVE
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1])
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order:\n");
for ( c = 0 ; c < n ; c++ )
printf("%d\n", array[c]);
return 0;
}
OBJECTIVE
#include <stdio.h>
int main()
{
int array[100], n, c, d, position, swap;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d", &array[c]);
for ( c = 0 ; c < ( n - 1 ) ; c++ )
{
position = c;
for ( d = c + 1 ; d < n ; d++ )
{
if ( array[position] > array[d] )
position = d;
}
if ( position != c )
{
swap = array[c];
array[c] = array[position];
array[position] = swap;
}
}
printf("Sorted list in ascending order:\n");
for ( c = 0 ; c < n ; c++ )
printf("%d\n", array[c]);
return 0;
}
OBJECTIVE
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t;
printf("Enter number of elements\n");
scanf("%d", &n);
printf("Enter %d integers\n", n);
for (c = 0; c < n; c++)
{
scanf("%d", &array[c]);
}
for (c = 1 ; c <= n - 1; c++)
{
d = c;
while ( d > 0 && array[d] < array[d-1])
{
t=array[d];
array[d]=array[d-1];
array[d-1]=t;
d--;
}
}
printf("Sorted list in ascending order:\n");
for (c = 0; c <= n - 1; c++)
{
printf("%d\n", array[c]);
}
return 0;
}
Dept. Of CSE 12 CS426
Experiment No 7
OBJECTIVE
#include<stdio.h>
void quicksort(int [10],int,int);
int main()
{
int x[20],size,i;
clrscr();
printf("Enter size of the array: ");
scanf("%d",&size);
printf("Enter %d elements: ",size);
for(i=0;i<size;i++)
scanf("%d",&x[i]);
quicksort(x,0,size-1);
printf("Sorted elements: ");
for(i=0;i<size;i++)
printf(" %d",x[i]);
return 0;
}
void quicksort(int x[10],int first,int last)
{
int pivot,j,temp,i;
if(first<last)
{
pivot=first;
i=first;
j=last;
while(i<j)
{
while(x[i]<=x[pivot]&&i<last)
i++;
while(x[j]>x[pivot])
j--;
if(i<j)
Dept. Of CSE 13 CS426
{
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);
}
}
OBJECTIVE
#include<stdio.h>
#include<conio.h>
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x = *y;
*y = temp;
}
void heapsort(int a[],int n)
{
int i,s,f;
for(i=1;i< n;++i)
{
s=i;
f=(s-1)/2;
while( a[f]< a[s])
{
swap(&a[f],&a[s]);
s=f;
if(s==0)
break;
f=(s-1)/2;
}
}
for(i=n-1;i>=1;--i)
{
swap(&a[0],&a[i]);
f=0;
s=1;
if(i==1)
break;
if(i>2)if(a[2]>a[1])s=2;
while( a[f]< a[s] )
Dept. Of CSE 15 CS426
{
swap(&a[f],&a[s]);
f=s;
s=2*f+1;
if(i>s+1 )if(a[s+1]>a[s])s=s+1;
if (s>=i)
break;
}
}
}
void main()
{
int a[100],n,i;
clrscr();
printf("\t\tHEAP SORT\n");
printf("\nEnter The Number Of Elements\t: ");
scanf("%d",&n);
printf("\nEnter Elements\n");
for(i=0;i< n;++i)
scanf("%d",&a[i]);
heapsort(a,n);
printf("\n\t\t\tSorted List\n");
for(i=0;i< n;++i)
printf("\t%d",a[i]);
getche();
}
Linked List:-
A linked list is a data structure consisting of a group of nodes which together represent a
sequence. Under the simplest form, each node is composed of a data and a reference (in other
words, a link) to the next node in the sequence; more complex variants add additional links.
This structure allows for efficient insertion or removal of elements from any position in the
sequence.
A linked list whose nodes contain two fields: an integer value and a link to the next node.
The last node is linked to a terminator used to signify the end of the list.
Linked lists are among the simplest and most common data structures. They can be used to
implement several other common abstract data types, including lists (the abstract data type),
stack, queues, associative arrays, and S-expressions, though it is not uncommon to
implement the other data structures directly without using a list as the basis of
implementation.
The principal benefit of a linked list over a conventional array is that the list elements can
easily be inserted or removed without reallocation or reorganization of the entire structure
because the data items need not be stored contiguously in memory or on disk. Linked lists
allow insertion and removal of nodes at any point in the list, and can do so with a constant
number of operations if the link previous to the link being added or removed is maintained
during list traversal.
On the other hand, simple linked lists by themselves do not allow random access to the data,
or any form of efficient indexing. Thus, many basic operations— such as obtaining the last
node of the list (assuming that the last node is not maintained as separate node reference in
the list structure), or finding a node that contains a given datum, or locating the place where
a new node should be inserted— may require scanning most or all of the list elements. The
advantages and disadvantages of using linked lists are as follows:-
Advantages:
Linked lists are a dynamic data structure, allocating the needed memory when the
program is initiated.
Insertion and deletion node operations are easily implemented in a linked list.
Linear data structures such as stacks and queues are easily executed with a linked list.
They can reduce access time and may expand in real time without memory overhead.
They have a tendency to waste memory due to pointers requiring extra storage space.
Nodes in a linked list must be read in order from the beginning as linked lists are
inherently sequential access.
Nodes are stored in contiguously, greatly increasing the time required to access
individual elements within the list.
Difficulties arise in linked lists when it comes to reverse traversing. Singly linked lists
are extremely difficult to navigate backwards, and while doubly linked lists are
somewhat easier to read, memory is wasted in allocating space for a back pointer.
OBJECTIVE
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct node
{
int info;
struct node *link;
}
*start;
void main()
{
int ch,n,m,pos,i;
clrscr();
start=NULL;
while(1)
{
printf("\n 1. Create");
printf("\n 2. insertatbeg");
printf("\n 3. insertatmiddle");
printf("\n 4. Delete");
printf("\n 5. Display");
printf("\n 6. Exit");
printf("\n Enter the choice:-");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("\n how many nodes u want to insert:-");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter the data:-");
scanf("%d",&m);
create(m);
free(temp);
return;
}
q=q->link;
}
if(q->link->info==data)
{
temp=q->link;
free(temp);
q->link=NULL;
return;
}
}
disp()
{
struct node *q;
if(start==NULL)
{
printf("List is Empty");
return;
}
q=start;
printf("List is:-\n");
while(q!=NULL)
{
printf("%d->",q->info);
q=q->link;
}
printf("NULL");
}
In a doubly linked list, each node contains, besides the next-node link, a second link field
pointing to the previous node in the sequence. The two links may be called forward(s) and
backwards, or next and prev(previous).
A doubly linked list whose nodes contain three fields: an integer value, the link forward to
the next node, and the link backward to the previous node
Experiment No 10
OBJECTIVE
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
struct Node *prev;
}node;
void insert(node *pointer, int data)
{
while(pointer->next!=NULL)
{
pointer = pointer -> next;
}
pointer->next = (node *)malloc(sizeof(node));
(pointer->next)->prev = pointer;
pointer = pointer->next;
pointer->data = data;
pointer->next = NULL;
}
int find(node *pointer, int key)
{
}
}
}
}
A circular linked list, In the case of a circular doubly linked list, the only change that occurs
is that the end, or "tail", of the said list is linked back to the front, or "head", of the list and
vice versa.
Experiment No 11
OBJECTIVE
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}node;
void insert(node *pointer, int data)
{
node *start = pointer;
while(pointer->next!=start)
{
pointer = pointer -> next;
}
pointer->next = (node *)malloc(sizeof(node));
pointer = pointer->next;
pointer->data = data;
pointer->next = start;
}
int find(node *pointer, int key)
{
node *start = pointer;
pointer = pointer -> next;
while(pointer!=start)
}
}
}
}
Stack:-
A stack is a particular kind of abstract data type or collection in which the principal (or only)
operations on the collection are the addition of an entity to the collection, known as push and
removal of an entity, known as pop. The relation between the push and pop operations is
such that the stack is a Last-In-First-Out (LIFO) data structure. In a LIFO data structure, the
last element added to the structure must be the first one to be removed. This is equivalent to
the requirement that, considered as a linear data structure, or more abstractly a sequential
collection, the push and pop operations occur only at one end of the structure, referred to as
the top of the stack. Often a peek or top operation is also implemented, returning the value of
the top element without removing it.
A stack may be implemented to have a bounded capacity. If the stack is full and does not
contain enough space to accept an entity to be pushed, the stack is then considered to be in
an overflow state. The pop operation removes an item from the top of the stack. A pop either
reveals previously concealed items or results in an empty stack, but, if the stack is empty, it
goes into underflow state, which means no items are present in stack to be removed.
A stack is a restricted data structure, because only a small number of operations are
performed on it. The nature of the pop and push operations also mean that stack elements
have a natural order. Elements are removed from the stack in the reverse order to the order of
their addition. Therefore, the lower elements are those that have been on the stack the
longest.
OBJECTIVE
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 5
int stack[MAX_SIZE];
void push();
int pop();
void traverse();
int is_empty();
int top_element();
int top = -1;
main()
{
int element, choice;
while(1)
{
printf("Stack Operations.\n");
printf("1. Insert into stack (Push operation).\n");
printf("2. Delete from stack (Pop operation).\n");
printf("3. Print top element of stack.\n");
printf("4. Check if stack is empty.\n");
printf("5. Traverse stack.\n");
printf("6. Exit.\n");
printf("Enter your choice.\n");
scanf("%d",&choice);
switch ( choice )
{
case 1:
if ( top == MAX_SIZE - 1 )
printf("Error: Overflow\n\n");
else
{
printf("Enter the value to insert.\n");
case 2:
if ( top == -1 )
printf("Error: Underflow.\n\n");
else
{
element = pop();
printf("Element removed from stack is %d.\n", element);
}
break;
case 3:
if(!is_empty())
{
element = top_element();
printf("Element at the top of stack is %d\n\n", element);
}
else
printf("Stack is empty.\n\n");
break;
case 4:
if(is_empty())
printf("Stack is empty.\n\n");
else
printf("Stack is not empty.\n\n");
break;
case 5:
traverse();
break;
case 6:
exit(0);
}
}
}
void push(int value)
{
top++;
stack[top] = value;
}
int pop()
{
Queue:-
A queue is a particular kind of abstract data type or collection in which the entities in the
collection are kept in order and the principal (or only) operations on the collection are the
addition of entities to the rear terminal position, known as en-queue, and removal of entities
from the front terminal position, known as de-queue. This makes the queue a First-In-First-
Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will
be the first one to be removed. This is equivalent to the requirement that once a new element
is added, all elements that were added before have to be removed before the new element can
be removed. Often a peek or front operation is also entered, returning the value of the front
element without de-queuing it. A queue is an example of a linear data structure, or more
abstractly a sequential collection.
Queues provide services in computer science, transport, and operations research where
various entities such as data, objects, persons, or events are stored and held to be processed
later. In these contexts, the queue performs the function of a buffer.
Queues are common in computer programs, where they are implemented as data structures
coupled with access routines, as an abstract data structure or in object-oriented languages as
classes. Common implementations are circular buffers and linked lists.
OBJECTIVE
#include<stdio.h>
#include<conio.h>
#define MAX 10
void insert(int);
int del();
int queue[MAX], rear=0, front=0;
void display();
int main()
{
char ch , a='y';
int choice, token;
printf("1.Insert");
printf("\n2.Delete");
printf("\n3.show or display");
do
{
printf("\nEnter your choice for the operation: ");
scanf("%d",&choice);
switch(choice)
{
case 1: insert(token);
display();
break;
case 2:
token=del();
printf("\nThe token deleted is %d",token);
display();
break;
case 3:
display();
break;
default:
printf("Wrong choice");
Dept. Of CSE 34 CS426
break;
}
printf("\nDo you want to continue(y/n):");
ch=getch();
}
while(ch=='y'||ch=='Y');
getch();
}
void display()
{
int i;
printf("\nThe queue elements are:");
for(i=rear;i<front;i++)
{
printf("%d ",queue[i]);
}
}
void insert(int token)
{
char a;
if(rear==MAX)
{
printf("\nQueue full");
return;
}
do
{
printf("\nEnter the token to be inserted:");
scanf("%d",&token);
queue[front]=token;
front=front+1;
printf("do you want to continue insertion Y/N");
a=getch();
}
while(a=='y');
}
int del()
{
int t;
if(front==rear)
{
printf("\nQueue empty");
return 0;
}
Circular Queue:-
In a standard queue data structure re-buffering problem occurs for each de-queue operation.
To solve this problem by joining the front and rear ends of a queue to make the queue as a
circular queue
Circular queue is a linear data structure. It follows FIFO principle.
In circular queue the last node is connected back to the first node to make a circle.
Circular linked list fallow the First In First Out principle
Elements are added at the rear end and the elements are deleted at front end of the
queue
Both the front and the rear pointers points to the beginning of the array.
It is also called as “Ring buffer”.
Items can inserted and deleted from a queue in O (1) time.
Using array:
In arrays the range of a subscript is 0 to n-1 where n is the maximum size. To make the array
as a circular array by making the subscript 0 as the next address of the subscript n-1 by using
the formula subscript = (subscript +1) % maximum size. In circular queue the front and rear
pointer are updated by using the above formula.
OBJECTIVE
#include<stdio.h>
#define max 5
int front,rear,q[max];
void enqueue(void);
void dequeue(void);
void qdisplay(void);
void main(void)
{
int c;
clrscr();
front=rear=-1;
do
{
printf("1:insert\n2:deletion\n3:display\n4:exit\nenter choice:");
scanf("%d",&c);
switch(c)
{
case 1:enqueue();break;
case 2:dequeue();break;
case 3:qdisplay();break;
case 4:printf("pgm ends\n");break;
default:printf("wrong choice\n");break;
}
}while(c!=4);
getch();
}
void enqueue(void)
{
int x;
if((front==0&&rear==max-1)||(front==rear+1))
{
printf("Queue is overflow\n");return;
printf("%d\n",q[i]);
}
printf("%d\n",q[rear]);
return;
}
Tree:-
A tree is a widely used abstract data type (ADT) or data structure implementing this ADT
that simulates a hierarchical tree structure, with a root value and sub-trees of children,
represented as a set of linked nodes.
A tree data structure can be defined recursively (locally) as a collection of nodes (starting at a
root node), where each node is a data structure consisting of a value, together with a list of
references to nodes (the "children"), with the constraints that no reference is duplicated, and
none points to the root.
Alternatively, a tree can be defined abstractly as a whole (globally) as an ordered tree, with a
value assigned to each node. Both these perspectives are useful: while a tree can be analyzed
mathematically as a whole, when actually represented as a data structure it is usually
represented and worked with separately by node (rather than as a list of nodes and an
adjacency list of edges between nodes, as one may represent a digraph, for instance). For
example, looking at a tree as a whole, one can talk about "the parent node" of a given node,
but in general as a data structure a given node only contains the list of its children, but does
not contain a reference to its parent
There are three types of depth-first traversal: pre-order, in-order, and post-order. For a binary
tree, they are defined as operations recursively at each node, starting with the root node as
follows:
Pre-order
Visit the root.
Traverse the left subtree.
Traverse the right subtree.
In-order (symmetric)
Traverse the left subtree.
Visit the root.
Traverse the right subtree.
Post-order
Traverse the left subtree.
Traverse the right subtree.
Visit the root.
OBJECTIVE
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct tree
{
int head;
struct tree *l, *r;
};
struct tree *r,*t;
int ch1,n,flag=0,in;
void main()
{
char ch='y';
r=NULL;
clrscr();
while (ch=='y')
{
clrscr();
printf("\n 1.Creat tree");
printf("\n 2.Traverse In-Order");
printf("\n 3.Traverse Pre-Order");
printf("\n 4.Traverse Post-Order");
printf("\n 5.Exit");
printf("\n Enter chioce");
scanf("%d",&ch1);
switch (ch1)
{
case 1:
if (insert(&r)==0)
break;
case 2:
printf("\n\n Left,Root,Right");
inorder(r);
getch();
Dept. Of CSE 42 CS426
break;
case 3:
printf("\n \n Root,Left,Right");
preorder(r);
getch();
break;
case 4:
printf("\n\n Left,Right,Root");
postorder(r);
getch();
break;
case 5:
exit();
default :
printf(" Wrong Choice ");
}// switch close
}// while clsoe
getch();
} //main close
Graph:-
BFS:-
In graph theory, breadth-first search (BFS) is a strategy for searching in a graph when search
is limited to essentially two operations: (a) visit and inspect a node of a graph; (b) gain
access to visit the nodes that neighbor the currently visited node. The BFS begins at a root
node and inspects all the neighboring nodes. Then for each of those neighbor nodes in turn, it
inspects their neighbor nodes which were unvisited, and so on. Compare BFS with the
equivalent, but more memory-efficient Iterative deepening depth-first search and contrast
with depth-first search.
DFS:-
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data
structures. One starts at the root (selecting some arbitrary node as the root in the case of a
graph) and explores as far as possible along each branch before backtracking.
OBJECTIVE
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
void input();
void output();
int db(int);
void BFS(struct tree *);
struct tree
{
char node[10];
struct tree *left,*right;
} *temp, *root=NULL,*t,*q[25];
int d,a[10],jj,ii,ti,b,fi,ri;
char ch[10];
void main()
{
clrscr();
input();
output();
getch();
}
void input()
{
int n,m,r,i,f;
printf("Enter the no of depth:-");
scanf("%d",&d);
n=pow(2,d+1)-1;
for(i=1;i<=n;i++)
{
printf("Enter the %d node name:-",i);
scanf("%s",ch);
OBJECTIVE
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
void input();
void output();
int db(int);
void DFS(struct tree *);
struct tree
{
char node[10];
struct tree *left,*right;
} *temp, *root=NULL,*t,*s[25];
int d,a[10],jj,ii,ti,b,top;
char ch[10];
void main()
{
clrscr();
input();
output();
getch();
}
void input()
{
int n,m,r,i,f;
printf("Enter the no of depth:-");
scanf("%d",&d);
n=pow(2,d+1)-1;
for(i=1;i<=n;i++)
{
Dept. Of CSE 49 CS426
printf("Enter the %d node name:-",i);
scanf("%s",ch);
temp=(struct tree *)malloc(sizeof(struct tree));
strcpy(temp->node,ch);
temp->left=NULL;
temp->right=NULL;
if(root==NULL)
{
root=temp;
}
else
{
t=root;
r=db(i);
for(f=1;f<r;f++)
{
if(a[f]==0)
{
t=t->left;
}
else
{
t=t->right;
}
}
if(a[r]==0)
{
t->left=temp;
}
else
{
t->right=temp;
}
}
}
}
void output()
{
t=root;
printf("\n Enter the name Goal:-");
scanf("%s",ch);
DFS(t);
}
int db(int n)
Experiment No 18
OBJECTIVE
#include <stdio.h>
#include <string.h>
int match(char [], char []);
int main()
{
char a[100], b[100];
int position;
printf("Enter some text\n");
gets(a);
printf("Enter a string to find\n");
gets(b);
position = match(a, b);
if(position != -1)
{