Posts

Write C++ program using stack to check whether given expression is well parenthesized or not

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical C24: In any language program mostly syntax error occurs due to unbalancing delimiter such as (),{},[]. Write C++ program using stack to check whether given expression is well parenthesized or not ---------------------------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<iostream> using namespace std; #define bool int /* structure of a stack node */ struct sNode {    char data;    struct sNode *next; }; /* Function to push an item to stack*/ void push(struct sNode** top_ref, int new_data); /* Function to pop an item from stack*/ int pop(struct sNode** top_ref); /* Returns 1 if character1 and character2 are matching left    and right Parenthesis */ bool isMatchingPair(char character1, char character2) {    if (character1 == '(' && ch

Write C++ program to store first year percentage of students in array using Selection and Bubble sort

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical E35: Write C++ program to store first year percentage of students in array. Write function for sorting array of floating point numbers in ascending order using a) Selection Sort b) Bubble sort and display top five scores. ---------------------------------------------------------------------------------------------------------------------------------- #include<iostream> using namespace std; class sort { float m[30]; int i,j,n; public: void insert() { cout<<"ENTER NUMBER OF STUDENTS:"<<endl; cin>>n; cout<<"ENTER MARKS:"<<endl; for(i=0;i<n;i++) { cin>>m[i]; } } void display() { cout<<"ENTERED MARKS ARE:"<<endl; for(i=0;i<n;i++) cout<<m[i]<<endl; } void bubble() { float temp; for(i=0;i<n-1 ;i++) { for(j=0;j<(n-1)-i;j

Write C++ program to store first year percentage of students in array. Sort array of floating point numbers in ascending order using quick sort and display top five scores

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical E37 Write C++ program to store first year percentage of students in array. Sort array of floating point numbers in ascending order using quick sort and display top five scores. ---------------------------------------------------------------------------------------------------------------------------------- #include <iostream> using namespace std; int partition(float x[100],int lb,int ub) { float a,temp; int down,up; a=x[lb]; //a mai 0 index val down=lb; // up=ub; // while(down<up) { while (x[down]<=a && down<up) down++; while(x[up]>a) up--; if(down<up) { temp=x[down]; x[down]=x[up]; x[up]=temp; } } x[lb]=x[up]; x[up]=a; return up; } void quicksort(float x[100],int lb,int ub){ int j; if(lb<ub) { j=partition(x,lb,ub); quicksort(x,lb,j-1); quickso

Write C++ program for sparse matrix realization and operations on it- Transpose, Fast Transpose and addition of two matrices

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical A11: Write C++ program for sparse matrix realization and operations on it- Transpose, Fast Transpose and addition of two matrices ---------------------------------------------------------------------------------------------------------------------------------- #include<iostream> using namespace std; class sparse { public: int a[30][30],b[30][30],t[30][30],c[30][30],d[30][30],e[30][30],al[30][3]; int n,m,g,h,q,y; int i,j,l,p,f,x,z,n1,z1; //note the 2d normanl matrix are a and c while the b and d are their sparse matrix respectively. void intake() { cout<<"enter the rows of the 2-dimentional matrix "<<endl; cin>>n; cout<<"enter the column of the 2-dimentional matrix "<<endl; cin>>m; for(i=0;i<n;i++) { cout<<"enter the element of "<<i<<"th row:"

Write C++ program for simulating job queue. Write functions to add job and delete job from queue.

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical D28: Queues are frequently used in computer programming, and a typical example is the creation of a job queue by an operating system. If the operating system does not use priorities, then the jobs are processed in the order they enter the system. Write C++ program for simulating job queue. Write functions to add job and delete job from queue. ---------------------------------------------------------------------------------------------------------------------------------- #include <iostream> #define MAX 10 using namespace std; struct queue {       int data[MAX]; int front,rear; }; class Queue {    struct queue q;    public:       Queue(){q.front=q.rear=-1;}       int isempty();       int isfull();       void enqueue(int);       int delqueue();       void display(); }; int Queue::isempty() { return(q.front==q.rear)?1:0; } int Queue::isfull() {    return(q.re

Implement C++ program for expression conversion as infix to postfix and its evaluation using stack.

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical C25: Implement C++ program for expression conversion as infix to postfix and its evaluation using stack based on given conditions i. Operands and operator, both must be single character. ii. Input Postfix expression must be in a desired format. iii. Only '+', '-', '*' and '/ ' operators are expected. ---------------------------------------------------------------------------------------------------------------------------------- #include<iostream> #include<conio.h> using namespace std; class stack {  public:   char stack_array[50];   int top;   stack()   {     top=-1;   } void push(char symbol) {  if(full())       cout<<"\nStack overflow:\n";     else     { top=top+1;       stack_array[top]=symbol;      } } char pop() {   if(empty())        return('#');         // Return value '#' indica

Write C++ program to store and search roll numbers of student in array who attended training program in random order

Second Year Computer Engineering Data Structure Programs: Data Structure Lab: Practical E32: Write C++ program to store roll numbers of student in array who attended training program in random order. Write function for- a) Searching whether particular student attended training program or not using linear search and sentinel search. b) Searching whether particular student attended training program or not using binary search and Fibonacci search ---------------------------------------------------------------------------------------------------------------------------------- #include<iostream> using namespace std; class search {  public:         int n,i,data[50],son[50],sortdata[50],s;  void intake() {     cout<<"Enter No. of Elements=";  cin>>n;  cout<<"\nEnter Elements=\n";  for(i=1;i<=n;i++)  {   cin>>data[i];      son[i]=data[i];  } } void search_lini(int item) {