Professional Documents
Culture Documents
h>
#include<stdlib.h>
#include<string.h>
return 1;
return 2;
return 3;
else
return 0;
char stack[100];
int index = 0;
char ch = infix[i];
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
prefix[index++] = ch;
if (ch == '(') {
stack[++top] = ch;
if (ch == ')') {
prefix[index++] = stack[top--];
stack[++top] = ch;
prefix[index++] = stack[top--];
prefix[index] = '\0';
int main() {
char infix[100];
char prefix[100];
scanf("%s", infix);
strrev(infix);
infixToPrefix(infix, prefix);
strrev(prefix);
#include<stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
for(int i=0;i<strlen(str);++i)
return false;
return true;
char stack[MAX_SIZE];
int top=-1;
for(int i=0;i<strlen(str);++i)
stack[++top]=str[i];
if(top==-1)
return false;
char topchar=stack[top--];
if(str[i]!=')' || str[i]!=']'||str[i]!='}'||str[i]!='>')
return false;
return top==-1;
int main()
int size;
scanf("%d",&size);
char str[size];
printf("enter string:");
scanf("%s",str);
if(!isValid(str))
printf("invalid");
}
else if(isBalanced(str))
printf("balanced");
else
printf("not balanced:");
return 0;
#include<stdio.h>
int data;
}Node;
Node* newNode=(Node*)malloc(sizeof(Node));
newNode->data=value;
newNode->next=NULL;
return newNode;
Node* newNode=createNode(value);
if(head==NULL)
return newNode;
Node* current=head;
while(current->next!=NULL)
current=current->next;
current->next=newNode;
return head;
if(head==NULL)
return head;
if(head->data==value)
Node* temp=head;
head=head->next;
free(temp);
return head;
Node* current=head;
{
current=current->next;
if(current->next==NULL)
return head;
Node*temp=current->next;
current->next=current->next->next;
free(temp);
return head;
if(head==NULL)
return head;
Node* slow=head;
Node* fast=head;
slow=slow->next;
fast=fast->next->next;
return slow;
{
Node* current=head;
Node* prev=NULL;
Node* next=NULL;
while(current!=NULL)
next=current->next;
current->next=prev;
prev=current;
current=next;
return prev;
if(head==NULL || head->next==NULL)
return head;
Node* rev=recRev(head->next);
head->next=NULL;
return rev;
Node* displayList(Node*head)
Node* current=head;
while(current!=NULL)
printf("%d",current->data );
current=current->next;
}
printf("\n");
int main()
Node* head=NULL;
head=insertend(head,40);
head=insertend(head,50);
head=insertend(head,90);
if (middleNode != NULL)
printf("%d\n", middleNode->data);
else
printf("List is empty.\n");
head=reverse(head);
head=recRev(head);
displayList(head);
return 0;
#include<stdio.h>
#include <stdlib.h>
int data;
}Node;
Node* newNode=(Node*)malloc(sizeof(Node));
newNode->data=val;
newNode->left=NULL;
newNode->right=NULL;
return newNode;
Node* newNode=createNew(val);
if(root==NULL)
return newNode;
if(val<root->data)
root->left=insertTree(root->left,val);
}
else if(val>root->data)
root->right=insertTree(root->right,val);
return root;
if(root!=NULL)
inorder(root->left);
printf("%d",root->data);
inorder(root->right);
while(root->left!=NULL)
root=root->left;
return root;
while(root->right!=NULL)
{
root=root->right;
return root;
if(root==NULL)
return root;
else if(val<root->data)
root->left=deleteNode(root->left,val);
else if(val>root->data)
root->right=deleteNode(root->right,val);
else
if(root->left==NULL)
Node* temp=root->right;
free(root);
return temp;
else if(root->right==NULL)
Node* temp=root->left;
free(root);
return temp;
Node * temp=findMin(root->right);
root->data=temp->data;
root->right=deleteNode(root->right,temp->data);
if(root==NULL)
return root;
if(val<root->data)
return search(root->left,val);
else if(val>root->data)
return search(root->right,val);
else
return root;
}
Node* kth(Node* root,int k,int *count)
if(root!=NULL)
Node* right=kth(root,k,count);
if(right!=NULL)
return right;
(*count)++;
if(count==k)
return root;
return kth(root->right,k,count);
return NULL;
if(root==NULL)
return NULL;
if(root->data>n1&& root->data>n2)
return Lca(root->left,n1,n2);
if(root->data<n1&& root->data<n2)
return Lca(root->right,n1,n2);
return root;
}
int countMult(Node* root,int k)
if(root==NULL)
return 0;
int count=0;
if(root->data%k==0)
count++;
count+=countMult(root->left,k);
count+=countMult(root->right,k);
return count;
int orig=num;
int rev=0;
while(num)
rev=rev*10+num%10;
num/=10;
return orig==rev;
int count=0;
Node* stack[100];
int top=-1;
while(root!=NULL||top!=-1)
while(root!=NULL)
stack[++top]=root;
root=root->left;
root=stack[top--];
if(isPalin(root->data))
count++;
root=root->right;
return count;
if(root!=NULL)
freeBST(root->left);
freeBST(root->right);
free(root);
}
int main()
inorder(root);
printf("\n");
inorder(root);
printf("\n");
int keyToSearch;
scanf("%d", &keyToSearch);
Node* srch=search(root,keyToSearch);
if(srch!=NULL)
else
{
Node* max=findMax(root);
int k;
printf("Enter the value of k for kth smallest and kth largest: ");
scanf("%d", &k);
int count = 0;
printf("%d",max->data);
if (k1 != NULL)
else
freeBST(root);
return 0;