All Programs
All Programs
#include<iostream>
#include<string.h>
#define max 50
class STACK
private:
char a[max];
int top;
public:
STACK()
top=-1;
void push(char);
void reverse();
void convert(char[]);
void palindrome();
};
void STACK::push(char c)
top++;
a[top] = c;
a[top+1]='\0';
void STACK::reverse()
char str[max];
cout<<a[i];
str[j]=a[i];
cout<<endl;
(int)str[j] <=90 ))
}else
str[k] = str[j];
k++;
str[k]='\0';
void STACK::palindrome()
char str[max];
int i,j;
str[j]=a[i];
str[j]='\0';
if(strcmp(str,a) == 0)
cout<<"\n\nString is palindrome...";
else
int main()
STACK stack;
char str[max];
int i=0;
cin.getline(str , 50);
stack.convert(str);
while(str[i] != '\0')
stack.push(str[i]);
i++;
stack.palindrome();
stack.reverse();
}
Exp 4
def Selection_Sort(marks):
for i in range(len(marks)):
min_idx = i
min_idx = j
for i in range(len(marks)):
print(marks[i])
#<--------------------------------------------------------------------------------------->
def Bubble_Sort(marks):
n = len(marks)
for i in range(len(marks)):
print(marks[i])
#<--------------------------------------------------------------------------------------->
def top_five_marks(marks):
print(*marks[::-1], sep="\n")
#<---------------------------------------------------------------------------------------->
# Main
marks=[]
print("Enter marks for",n,"students (Press ENTER after every students marks): ")
ele = float(input())
marks.append(ele)
print(marks)
flag=1;
while flag==1:
print("\n---------------MENU---------------")
print("3. Exit")
if ch==1:
Selection_Sort(marks)
a=input("\nDo you want to display top marks from the list (yes/no) : ")
if a=='yes':
top_five_marks(marks)
else:
flag=0
elif ch==2:
Bubble_Sort(marks)
a = input("\nDo you want to display top five marks from the list (yes/no) : ")
if a == 'yes':
top_five_marks(marks)
else:
flag = 0
elif ch==3:
flag=0
else:
print("\nEnter a valid choice!!")
flag=0
Exp 6
def input_percentage():
perc = []
for i in range(number_of_students):
return perc
#<--------------------------------------------------------------------------------------------------------------------->
def print_percentage(perc):
for i in range(len(perc)):
print(perc[i],sep = "\n")
#<--------------------------------------------------------------------------------------------------------------------->
def percentage_partition(perc,start,end):
pivot = perc[start]
lower_bound = start + 1
upper_bound = end
while True:
lower_bound += 1
upper_bound -= 1
perc[lower_bound],perc[upper_bound] = perc[upper_bound],perc[lower_bound]
else:
break
perc[start],perc[upper_bound] = perc[upper_bound],perc[start]
return upper_bound
#<--------------------------------------------------------------------------------------------------------------------->
def Quick_Sort(perc,start,end):
partition = percentage_partition(perc,start,end)
Quick_Sort(perc,start,partition-1)
Quick_Sort(perc,partition+1,end)
return perc
#<--------------------------------------------------------------------------------------------------------------------->
def display_top_five(perc):
if len(perc) < 5:
else:
print(perc[i],sep = "\n")
#<--------------------------------------------------------------------------------------------------------------------->
# Main
unsorted_percentage = []
sorted_percentage = []
flag = 1
while flag == 1:
print("\n--------------------MENU--------------------")
print("4. Exit")
ch = int(input("Enter your choice (from 1 to 4) : "))
if ch == 1:
unsorted_percentage = input_percentage()
elif ch == 2:
print_percentage(unsorted_percentage)
elif ch == 3:
sorted_percentage = Quick_Sort(unsorted_percentage,0,len(unsorted_percentage)-1)
print_percentage(sorted_percentage)
a = input("Do you want to display the Top 5 Percentages of Students (yes/no) : ")
if a == 'yes':
display_top_five(sorted_percentage)
elif ch == 4:
flag = 0
else:
print("Invalid Choice!!")
#<-----------------------------------------------END OF PROGRAM-------------------------------------------------------->
Exp 8
#include<iostream>
int start;
int end;
int min;
int max;
int flag;
}*head;
class App_Shedule
public:
void create_Shed();
void display_Shed();
void book_App();
void cancel_App();
void sort_App();
}A1;
int main()
int ch;
char ans;
do
cin>>ch;
switch(ch)
case 1: A1.create_Shed();
break;
case 2: A1.display_Shed();
break;
case 3: A1.book_App();
break;
case 4: A1.cancel_App();
break;
case 5: A1.sort_App();
break;
cin>>ans;
}while(ans == 'y');
int i;
head = NULL;
cin>>size;
cout<<"\n\n\t Enter Start Time: "; // Step 2: Assign Data & Address
cin>>temp->start;
cin>>temp->end;
cin>>temp->min;
cin>>temp->max;
temp->flag = 0;
temp->next = NULL;
if(head == NULL)
head = temp;
last = head;
else
last->next = temp;
last = last->next;
{
int cnt = 1;
cout<<"\n\n\t Srno.\tStart\tEnd\tMin_Dur\tMax_Dur\tStatus";
temp = head;
while(temp != NULL)
cout<<"\n\n\t "<<cnt;
cout<<"\t "<<temp->start;
cout<<"\t "<<temp->end;
cout<<"\t "<<temp->min;
cout<<"\t "<<temp->max;
if(temp->flag)
cout<<"\t-Booked-";
else
cout<<"\t--Free--";
temp = temp->next;
cnt++;
int start;
cin>>start;
temp = head;
while(temp != NULL)
if(start == temp->start)
if(temp->flag == 0)
temp->flag = 1;
else
temp = temp->next;
int start;
temp = head;
while(temp != NULL)
if(start == temp->start)
if(temp->flag == 1)
temp->flag = 0;
else
temp = temp->next;
int i,j,val;
temp = head;
while(temp->next != NULL)
val = temp->start;
temp->start = temp->next->start;
temp->next->start = val;
val = temp->end;
temp->end = temp->next->end;
temp->next->end = val;
val = temp->min;
temp->min = temp->next->min;
temp->next->min = val;
val = temp->max;
temp->max = temp->next->max;
temp->next->max = val;
temp = temp->next;
}
Exp 10
#include<iostream>
#include<cctype>
#include<stack>
switch (operate) {
default : return 0;
switch (ch) {
case '/':
case '+':
default : return 0;
int i = 0;
char ch;
int val;
ch = postfix[i];
if (isdigit(ch)) {
// we saw an operand
s.push(ch-'0');
else {
// we saw an operator
// operator
s.pop();
s.pop();
s.push(val);
i++;
return val;
// main
int main() {
int i=0;
// cout<<"Postfix 0"<<postfix[i];
while(postfix[i]!='\0')
if(getWeight(postfix[i])==0)
cin>>postfix[i];
i++;
cout<<endl;
return 0;
}
Exp 12
#include<iostream>
#include<stdio.h>
#define MAX 10
struct que
int arr[MAX];
int front,rear;
};
q->front=1;
q->rear=1;
int i;
i=q.front;
while(i!=q.rear)
cout<<"\t"<<q.arr[i];
i=(i+1)%MAX;
cout<<"\t"<<q.arr[q.rear];
}
return q.rear==-1?1:0;
return(q.rear+1)%MAX==q.front?1:0;
if(isempty(*q))
q->front=q->rear=0;
q->arr[q->front]=data;
else
q->front=(q->front-1+MAX)%MAX;
q->arr[q->front]=data;
if(isempty(*q))
q->front=q->rear=0;
q->arr[q->rear]=data;
}
else
q->rear=(q->rear+1)%MAX;
q->arr[q->rear]=data;
int data1;
data1=q->arr[q->front];
if(q->front==q->rear)
init(q);
else
q->front=(q->front+1)%MAX;
return data1;
int data1;
data1=q->arr[q->rear];
if(q->front==q->rear)
init(q);
else
q->rear=(q->rear-1+MAX)%MAX;
return data1;
int main()
{
struct que q;
init(&q);
while(ch!=6)
cin>>ch;
switch(ch)
case 1:
cin>>data;
addf(&q,data);
break;
case 2:
cin>>data;
addr(&q,data);
break;
case 3:
if (isempty(q))
cout<<"\nDequeue is empty";
else
data=delf(&q);
break;
case 4:
if (isempty(q))
cout<<"\nDequeue is empty";
else
data=delr(&q);
break;
case 5:
if (isempty(q))
cout<<"\nDequeue is empty!!!";
else
print(q);
break;
return 0;