The document discusses the implementation of queue operations using pointers and arrays in C. It defines the queue data structure using a struct containing a data element and pointer to the next node. Functions are defined to add, remove and check for empty/full as well as display the queue elements. A similar implementation is shown using arrays instead of pointers by defining a queue struct containing the front, rear indexes and size.
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdfrozakashif85
Data Structures
PLEASE USING THIS C++ PROGRAM BELOW, I NEED HELP ON IMPLEMENTING
BOTH QUEUE AND STACK TO PRINT \"I able\"
REVERSE/BACKWARDS(PALINDROME)
#include
#include
using namespace std;
struct st
{
int year;
st *next;
};
class queue
{
public:
int sz,i = 0;
char chr[100];
queue()
{
//constructor for initializing front and rear to NULL
front = NULL;
rear = NULL;
cout << \"enter size of queue: \";
cin >> sz;
}
// ~queue()
// {
//
// }
// in the enterqueue, create a new node, assign value and add it to queue
// if F = R = NULL the ( ) else ( )
void enterqueue(int yr, char el)
{
//inserting into queue if queue not overflow
if(i >= sz)
{
cout << \"queue over flow\";
return;
}
if (front == NULL )
{
front = new st;
front->next = NULL;
front->year = yr;
rear = front;
chr[i] = el;
i++;
}
else
{
st *temp = new st;
temp->year = yr;
rear->next = temp;
rear = temp;
chr[i] = el;
i++;
}
}
char deletequeue()
{
//delete front data from queue if data in the queue
char tr;
int j = 0;
st *temp;
temp = front;
if( front == NULL)
{
cout << \"queue under flow\";
return \'a\';
}
if(front == rear)
{
front = rear = NULL;
return \'a\';
}
front = front->next;
delete temp;
tr = chr[0];
i--;
for(j = 0; j < i; j++)
{
chr[j] = chr[j+1];
}
chr[j] = \'\\0\';
return tr;
}
bool isempty()
{
//it shows whether queue is empty
if( front == NULL)
{
return true;
}
else
return false;
}
bool isfull()
{
//it shows whether queue is full
if(i == sz)
return true;
else
return false;
}
void display()
{
//it displays queue data with characters of queue if invalid choice is entered
st *tmp;
int j = 0;
cout << \"\ queue is:\ character \\tyear\";
for(tmp = front; tmp != rear; tmp = tmp->next, j++)
{
cout << \"\ \" << chr[j] << \" \" << tmp->year;
}
cout << \"\ \"<year;
}
private:
st *front, *rear;
};
int main()
{
//main method to call queue functions by choice
queue s1;
int ch,yr;
char el;
bool s;
while(1)
{
cout << \"\ 1.ENTERQUEUE\ 2.DELETEQUEUE\ 3.ISEMPTY\ 4.ISFULL\ 5.EXIT\ enter
your choice: \";
cin >> ch;
switch(ch)
{
case 1:
if(!s1.isfull())
{
cout << \"\ enter a year : \";
cin >> yr;
cout << \"\ enter a character : \";
cin >> el;
s1.enterqueue(yr, el);
}
else
cout << \"insertion not possible\";
break;
case 2:
s = s1.isempty();
if(!s)
{
el = s1.deletequeue();
cout << \"\ The character of queue \" << el <<\" is deleted\" << endl;
}
else
cout << \"\ queue is empty.deletion not possible\"<< endl;
break;
case 3:
s = s1.isempty();
if(s)
cout << \"\ queue is empty\" << endl;
else
cout << \"\ queue is not empty\" << endl;
break;
case 4:
s=s1.isfull();
if(s)
cout << \"\ queue is full\" << endl;
else
cout << \"\ queue is not full\" << endl;
break;
case 5:
exit(0);
default : cout << \"invalid choice\" << endl;
if(!s1.isempty())
s1.display();
}
}
return (0);
}
Solution
#include
#include
using namespace std;
struct st
{
int year;
st *next;
};
class queue
{
public:
//int sz,i=0;//modified //code modified here// everything is fine with the code except this...
queue is implemented correctly
//you can .
solution in c++program Program to implement a queue using two .pdfbrijmote
solution in c++
program
/* Program to implement a queue using two stacks */
#include
#include
using namespace std;
/* structure of a stack node */
struct sNode
{
int 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);
/* structure of queue having two stacks */
struct queue
{
struct sNode *stack1;
struct sNode *stack2;
};
/* Function to enqueue an item to queue */
void enQueue(struct queue *q, int x)
{
push(&q->stack1, x);
}
/* Function to dequeue an item from queue */
int deQueue(struct queue *q)
{
int x;
/* If both stacks are empty then error */
if(q->stack1 == NULL && q->stack2 == NULL)
{
printf(\"Q is empty\");
getchar();
exit(0);
}
/* Move elements from satck1 to stack 2 only if
stack2 is empty */
if(q->stack2 == NULL)
{
while(q->stack1 != NULL)
{
x = pop(&q->stack1);
push(&q->stack2, x);
}
}
x = pop(&q->stack2);
return x;
}
/* Function to push an item to stack*/
void push(struct sNode** top_ref, int new_data)
{
/* allocate node */
struct sNode* new_node =
(struct sNode*) malloc(sizeof(struct sNode));
if(new_node == NULL)
{
printf(\"Stack is empty \ \");
getchar();
exit(0);
}
else{
/* put in the data */
new_node->data = new_data;
/* link the old list off the new node */
new_node->next = (*top_ref);
/* move the head to point to the new node */
(*top_ref) = new_node;
}
}
/* Function to pop an item from stack*/
int pop(struct sNode** top_ref)
{
int res;
struct sNode *top;
/*If stack is empty then error */
if(*top_ref == NULL)
{
printf(\"Stack overflow \ \");
getchar();
exit(0);
}
else
{
top = *top_ref;
res = top->data;
*top_ref = top->next;
free(top);
return res;
}
}
/* Driver function to test anove functions */
int main()
{
/* Create a queue with items 1 2 3*/
struct queue *q = (struct queue*)malloc(sizeof(struct queue));
q->stack1 = NULL;
q->stack2 = NULL;
for(int i=0;i<15;i++)
{
enQueue(q, i);
}
//enQueue(q, 2);
//enQueue(q, 3);
//enQueue(q,4);
/* Dequeue items */
printf(\"the dequeue items\");
for(int i=0;i<16;i++)
{
printf(\"%d \", deQueue(q));
//printf(\"%d \", deQueue(q));
}
getchar();
}
output
the dequeue items
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
q is empty
Solution
solution in c++
program
/* Program to implement a queue using two stacks */
#include
#include
using namespace std;
/* structure of a stack node */
struct sNode
{
int 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);
/* structure of queue having two stacks */
struct queue
{
struct sNode *stack1;
struct sNode *stack2;
};
/* Function to enqueue an item to queue */
void enQueue(struct queue *q, int x)
{
push(&q->stack1, x);
}
/* Function to dequeue an item from queue */
int deQueue(struct queue *q)
{
int x;
/* If both stacks are empty then error */
if(q->stack1 == NULL && q->stack2 == NULL)
{
printf(\"Q .
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf(\"Enter the number of elements : \");
scanf(\"%d\",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf(\"Increment=%d \ \",incr);
for (i = 0; i < n; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
incr=incr-2; /*Decrease the increment*/
}/*End of while*/
printf(\"Sorted list is :\ \");
for (i = 0; i < n; i++)
printf(\"%d \", arr[i]);
printf(\"\ \");
}/*End of main()*/
redix sort
/*Program of sorting using radix sort*/
# include
# include
struct node
{
int info ;
struct node *link;
}*start=NULL;
main()
{
struct node *tmp,*q;
int i,n,item;
printf(\"Enter the number of elements in the list : \");
scanf(\"%d\", &n);
for(i=0;iinfo=item;
tmp->link=NULL;
if(start==NULL) /* Inserting first element */
start=tmp;
else
{
q=start;
while(q->link!=NULL)
q=q->link;
q->link=tmp;
}
}/*End of for*/
printf(\"Unsorted list is :\ \");
display();
radix_sort();
printf(\"Sorted list is :\ \");
display ();
}/*End of main()*/
display()
{
struct node *p=start;
while( p !=NULL)
{
printf(\"%d \", p->info);
p= p->link;
}
printf(\"\ \");
}/*End of display()*/
radix_sort()
{
int i,k,dig,maxdig,mindig,least_sig,most_sig;
struct node *p, *rear[10], *front[10];
least_sig=1;
most_sig=large_dig(start);
for(k = least_sig; k <= most_sig ; k++)
{
printf(\"PASS %d : Examining %dth digit from right \",k,k);
for(i = 0 ; i <= 9 ; i++)
{
rear[i] = NULL;
front[i] = NULL ;
}
maxdig=0;
mindig=9;
p = start ;
while( p != NULL)
{
/*Find kth digit in the number*/
dig = digit(p->info, k);
if(dig>maxdig)
maxdig=dig;
if(diglink = p ;
rear[dig] = p ;
p=p->link;/*Go to next number in the list*/
}/*End while */
/* maxdig and mindig are the maximum amd minimum
digits of the kth digits of all the numbers*/
printf(\"mindig=%d maxdig=%d\ \",mindig,maxdig);
/*Join all the queues to form the new linked list*/
start=front[mindig];
for(i=mindig;ilink=front[i+1];
else
rear[i+1]=rear[i];
}
rear[maxdig]->link=NULL;
printf(\"New list : \");
display();
}/* End for */
}/*End of radix_sort*/
/* This function finds number of digits in the largest element of the list */
int large_dig()
{
struct node *p=start ;
int large = 0,ndig = 0 ;
while(p != NULL)
{
if(p ->info > large)
large = p->info;
p = p->link ;
}
printf(\"Largest Element is %d , \",large);
while(large != 0)
{
ndig++;
large = large/10 ;
}
printf(\"Number of digits in it are %d\ \",ndig);
return(ndig);
} /*End of large_dig()*/
/*This function returns kth digit of a number*/
int digit(int number, int k)
{
int digit, i ;
for(i = 1 ; i <=k ; i++)
{
digit = number % 10 ;
number = number /10 ;
}
return(digit);
}/*End of digit()*/
Solution
/* Program of sorting using shell sort */
#include
#define MAX 20
main()
{
int arr[MAX], i,j,k,n,incr;
printf(\"Enter the number of elements : \");
scanf(\"%d\",&n);
for(i=0;i=1)
{
for(j=incr;j= 0 && k < arr[i]; i = i-incr)
arr[i+incr]=arr[i];
arr[i+incr]=k;
}
printf(\.
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
in this assignment you are asked to write a simple driver program and set of functions (maybein
a library) that can be performed on a binary search tree.
Your program should allow user to insert/delete integer values into the binary search tree along
with several other operations on the binary search tree. You can use the code given in slides. But
this time your key will be int! Specifically, your program will ask user to enter a command and
related parameters (if any) in a loop, and then perform the given commands. Here is the list of
commands that your program must implement:
* insert
*find\'
*delete
*list inorder
*list preorder
*list postorder
*list levelorder
* max
* min
* height
*count
* sum
*quit
As always, make sure you release (free) the dynamically allocated memories if you allocate any
memory in your programs. So, before submitting your program, run it with valgrind to see if
there is any memory leakage
//my proggram in C
struct tree_node {
int data;
struct tree_node *left, *right;
}
typedef struct nodeT {
int key;
struct nodeT *left, *right;
} nodeT, *treeT;
int main(){
while (TRUE) {
printf(\"> \");
line = GetLine();
ch = toupper(line[0]);
switch (ch) {
case \'I\': insert(); break;
case \'F\': find(); break;
case \'D\': delete(); break;
case \'LI\': listInorder; break;
case \'LPR\': listPreorder(); break;
case \'LPO\': listPostorder(); break;
case \'MAX\': max(); break;
case \'min\': min(); break;
case \'H\': height(); break;
case \'C\': count(); break;
case \'S\': sum(); break;
case \'Q\': exit(0);
default:printf(\"Illegal command\ \"); break;
}
}
}
nodeT *FindNode(nodeT *t, int key){
while(t !=NULL) {
if (key == t->key) return t;
if (key < t->key) {
t = t->left;
} else {
t = t->right;
}
return NULL;
}
void delete(nodeT **p){
nodeT
*target;
target=*p;
if (target->left==NULL && target->right==NULL) {
*p=NULL;
} else if (target->left == NULL) {
*p=target->right;
} else
if (target->right == NULL) {
*p=target->left;
} else {
/* target has two children, see next slide */
}
free(target);
}
void listInorder(nodeT *T){
if (t != NULL) {
DisplayTree(t->left);
printf(“%d “, t->key);
DisplayTree(t->right);
}
}
void listPreorder(nodeT *t) {
if (t != NULL) {
printf(“%d “, t->key);
DisplayTree(t->left);
DisplayTree(t->right);
}
}
void listPostOrder(nodeT *t){
if (t != NULL) {
DisplayTree(t->left);
DisplayTree(t->right);
printf(“%d “, t->key);
}
}
void intsert(nodeT **tptr, int key){
nodeT*t, *tmp;
t=*tptr;
if (t == NULL) {
tmp=New(nodeT*);
tmp->key = key;
tmp->left=tmp->right=NULL;
*tptr=tmp;
return;
}
if (key < t->key) {
InsertNode
(&t->left, key);
} else {
InsertNode(&t->right, key);
}
}
int height(nodeT *t){
if (t == NULL)
return 0;
else
return (1 + maximumof(
height(t->left),
height(t->right)) );
}
int sum(struct tree_node *p){
if (p == NULL)
return 0;
else
return (p->data +
sum(p->left) +
sum(p->right) );
}
Solution
1. /*
2. * Java Program to Implement Binary Search Tree
3. */
4.
5. import java.util.Scanner;
6.
7. /* Class BSTNode */
8. cl.
03 of 03 parts
Get Part 1 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-1
Get Part 2 from https://www.slideshare.net/ArunUmrao/notes-for-c-programming-for-bca-mca-b-sc-msc-be-amp-btech-1st-year-2
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, while a static type system prevents unintended operations. C provides constructs that map efficiently to typical machine instructions and has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computers, from supercomputers to PLCs and embedded system.
C++ Searching & Sorting5. Sort the following list using the select.pdfRahul04August
C++ Searching & Sorting
5. Sort the following list using the selection sort algorithm. Show the list after each iteration of
the outerforloop.
36, 55, 17, 35, 63, 85, 12, 48, 3, 66
6. Consider the following list: 5, 18, 21, 10, 55, 20
The first three keys are in order. To move 10 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
7. Consider the following list: 7, 28, 31, 40, 5, 20
The first four keys are in order. To move 5 to its proper position using the insertion sort as
described in this chapter, exactly how many key comparisons are executed?
8. Consider the following list: 28, 18, 21, 10, 25, 30, 12, 71, 32, 58, 15
This list is to be sorted using the insertion sort algorithm. Show the resulting list after six
passes of the sorting phase – that is, after six iterations of the for loop.
9. Perform the insertion sort algorithm using the following list of keys: 18, 8, 11, 9, 15, 20, 32,
61, 22, 48, 75, 83, 35, 3
Show the list after each iteration. Exactly how many key comparisons are executed to sort this
list using insertion sort?
10. a. The performance of bubble sort can be improved if we stop the sorting process as soon as
we find that in an iteration, no swapping of elements takes place. Write a function that
implements bubble sort algorithm using this fact.
b. Using the algorithm that you designed in part (a), find the number of iterations that are needed
to sort the list: 65, 14, 52, 43, 75, 25, 80, 90, 95.
11. Suppose that L is a sorted list of 4096 elements. What is the maximum number of
comparisons made by binary search to determine whether an item is in L?
12. Suppose that the elements of a list are in descending order, and they need to be put in
ascending order. Write a C++ function that takes as input an array of items in descending order
and the number of elements in the array. The function must not incorporate any sorting
algorithms, that is, no item comparisons should take place.
Solution
# include
# include
# include
#include
#include
#include
#include
// Function related to sorting in class sorting
class sorting
{
int array[50],array1[50],final[100],i,n,m,j;
public:
// Function to read an array
void read();
// Function to read arrays for merge sort
void read_mer();
// Function to display an array
void display();
// Function to perform bubble sort
void bub_sort();
// Function to perform selection sort
void Sel_sort();
// Function to perform insertion sort
void Ins_sort();
// Function to perform quick sort
void Qui_sort();
// Function to perform heap sort
void Heap_sort();
// Function to build a heap
void heap(int array[], int n);
// Function to interchange the value of root node with a
// child node in heap sort
void below_heap(int array[], int first, int last);
// Function to perform merges sort
void Mer_sort();
// Function to perform shell sort
void Shell_sort();
// Function to split the array into two halves during quick sort
void partition(int arra.
Given an expression string exp, write a java class ExpressionCheccke.pdfinfo382133
Given an expression string exp, write a java class ExpressionCheccker whose main method gets
exp in the input line of terminal and examines whether the pairs and the orders of ”(“,”)”,”[“,”]”
are correct in exp. For example, the program should print true for exp =“[()][()()]()” and false for
exp = “[(])”. ( Use stack)
Ans:
Algorithm:
1) Declare a character stack S.
2) Now traverse the expression string exp.
a) If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.
b) If the current character is a closing bracket (‘)’ or ‘}’ or ‘]’) then pop from stack and if the
popped character is the matching starting bracket then fine else parenthesis are not balanced.
3) After complete traversal, if there is some starting bracket left in stack then “not balanced”
Program:
#include
#include
#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 == \'(\' && character2 == \')\')
return 1;
else if (character1 == \'{\' && character2 == \'}\')
return 1;
else if (character1 == \'[\' && character2 == \']\')
return 1;
else
return 0;
}
/*Return 1 if expression has balanced Parenthesis */
bool areParenthesisBalanced(char exp[])
{
int i = 0;
/* Declare an empty character stack */
struct sNode *stack = NULL;
/* Traverse the given expression to check matching parenthesis */
while (exp[i])
{
/*If the exp[i] is a starting parenthesis then push it*/
if (exp[i] == \'{\' || exp[i] == \'(\' || exp[i] == \'[\')
push(&stack, exp[i]);
/* If exp[i] is a ending parenthesis then pop from stack and
check if the popped parenthesis is a matching pair*/
if (exp[i] == \'}\' || exp[i] == \')\' || exp[i] == \']\')
{
/*If we see an ending parenthesis without a pair then return false*/
if (stack == NULL)
return 0;
/* Pop the top element from stack, if it is not a pair
parenthesis of character then there is a mismatch.
This happens for expressions like {(}) */
else if ( !isMatchingPair(pop(&stack), exp[i]) )
return 0;
}
i++;
}
/* If there is something left in expression then there is a starting
parenthesis without a closing parenthesis */
if (stack == NULL)
return 1; /*balanced*/
else
return 0; /*not balanced*/
}
/* UTILITY FUNCTIONS */
/*driver program to test above functions*/
int main()
{
char exp[100] = \"{()}[]\";
if (areParenthesisBalanced(exp))
printf(\"\ Balanced \");
else
printf(\"\ Not Balanced \");
return 0;
}
/* Function to push an item to stack*/
void push(struct sNode** top_ref, int new_data)
{
/* allocate node */
struct sNode* new_node =
(struct sNode*) malloc(sizeof(struct sNode));
if (new_node == NULL)
{
printf(\"Stack overflow \ \");
getchar();
exit(0);
}
/* put in the data */
new_node.
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
//operating system ubuntu,linux,Mac
Program will work only if you give command like
sum 2 3 or
sum 4 (sub 4 3)
#include
#include
#include
#include
/*Sum function implementation*/
int sum(int number1,int number2){
return number1+number2;
}
/*sub function implementation*/
int sub(int number1,int number2){
return number1-number2;
}
/*mul function implementation*/
int mul(int number1,int number2){
return number1*number2;
}
/*divide function implementation*/
float divide(int number1,int number2){
if(number2==0){
printf(\"We can not divide by 0 \ \");
return 0.0f;
}
return (float)(number1/number2);
}
char *substring(char *string, int position, int length)
{
char *pointer;
int c;
pointer = malloc(length+1);
if (pointer == NULL)
{
printf(\"Unable to allocate memory.\ \");
exit(1);
}
for (c = 0 ; c < length ; c++)
{
*(pointer+c) = *(string+position-1);
string++;
}
*(pointer+c) = \'\\0\';
return pointer;
}
/*Main Function start*/
int main(int argc, char *argv[]){
/*Variable declarations*/
int number1,number2;
char *operator,*str1,*str2;
char line[50];
char s[2] = \" \";
int errorFlag=0;// checking if user entered more then one operands
while(1){
/*User input*/
printf(\"Please Enter the command \");
gets(line);
int len=0;
for(int i=0; line[i]!=\'\\0\'; ++i){len++;}
if(len==0){
return 1;
}
/*Spliting into Tokens*/
operator = strtok(line, \" \");
if(strcmp(operator,\"bye\")==0){
break;
}
/*String to integer --- token1*/
number1=atoi(strtok(NULL, s));
/*Removing ( and ) from String*/
str2=strtok(NULL, s);
char *content;int length=0;
for(int i=0; str2[i]!=\'\\0\'; ++i){length++;}
if(str2[0]==\'(\'){
content=substring(str2,2,length-1);
char *opr=content;
int n1=atoi(strtok(NULL, s));
int n2=atoi(strtok(NULL, s));
/*If user entered more then two operands then it will return some token otherwise it will
return NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf(\"You need to enter operator operand1 operand2 \ \");
errorFlag=1;
}else{
if(strcmp(opr,\"sum\")==0){
number2=sum(n1,n2);
}else if(strcmp(opr,\"sub\")==0){
number2=sub(n1,n2);
}else if(strcmp(opr,\"mul\")==0){
number2=mul(n1,n2);
} else if(strcmp(opr,\"div\")==0){
number2=divide(n1,n2);
}
}
}else{
number2=atoi(str2);
/*If user entered more then two operands then it will return some token otherwise it will return
NULL pointer*/
if(strtok(NULL, s)!=NULL){
printf(\"You need to enter operator operand1 operand2 \ \");
errorFlag=1;
}
}
if(errorFlag!=1){
/*Checking operator by strcmp function*/
if(strcmp(operator,\"sum\")==0){
printf(\"Result %d \ \",sum(number1,number2));
}else if(strcmp(operator,\"sub\")==0){
printf(\"Result %d \ \",sub(number1,number2));
}else if(strcmp(operator,\"mul\")==0){
printf(\"Result %d \ \",mul(number1,number2));
} else if(strcmp(operator,\"div\")==0){
printf(\"Result %.2f \ \",divide(number1,number2));
}
}
}
return 0;
}
/*******************Output***********************/
gopal@gopal:~/Desktop/chegg$ gcc Calculator.c
Calculator.c: In function ‘main’:
Calculator.c:67:3: warning: implici.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
The French Revolution Class 9 Study Material pdf free download
week-16x
1. /* Write C programs that implement Queue (its operations) using ii) Pointers */
#define true 1
#define false 0
#include<stdio.h>
#include<conio.h>
#include<process.h>
struct q_point
{
int ele;
struct q_point* n;
};
struct q_point *f_ptr = NULL;
int e_que(void);
void add_ele(int);
int rem_ele(void);
void show_ele();
/*main function*/
void main()
2. {
int ele,choice,j;
while(1)
{
clrscr();
printf("nn****IMPLEMENTATION OF QUEUE USING POINTERS****n");
printf("==============================================");
printf("ntt MENUn");
printf("==============================================");
printf("nt[1] To insert an element");
printf("nt[2] To remove an element");
printf("nt[3] To display all the elements");
printf("nt[4] Exit");
printf("nntEnter your choice:");
scanf("%d", &choice);
switch(choice)
{
case 1:
{
printf("ntElement to be inserted:");
scanf("%d",&ele);
add_ele(ele);
getch();
3. break;
}
case 2:
{
if(!e_que())
{
j=rem_ele();
printf("nt%d is removed from the queue",j);
getch();
}
else
{
printf("ntQueue is Empty.");
getch();
}
break;
}
case 3:
show_ele();
getch();
break;
4. case 4:
exit(1);
break;
default:
printf("ntInvalid choice.");
getch();
break;
}
}
}
/* Function to check if the queue is empty*/
int e_que(void)
{
if(f_ptr==NULL)
return true;
return false;
}
/* Function to add an element to the queue*/
void add_ele(int ele)
{
5. struct q_point *queue = (struct q_point*)malloc(sizeof(struct q_point));
queue->ele = ele;
queue->n = NULL;
if(f_ptr==NULL)
f_ptr = queue;
else
{
struct q_point* ptr;
ptr = f_ptr;
for(ptr=f_ptr ;ptr->n!=NULL; ptr=ptr->n);
ptr->n = queue;
}
}
/* Function to remove an element from the queue*/
int rem_ele()
{
struct q_point* queue=NULL;
if(e_que()==false)
{
int j = f_ptr->ele;
queue=f_ptr;
f_ptr = f_ptr->n;
free (queue);
6. return j;
}
else
{
printf("ntQueue is empty.");
return -9999;
}
}
/* Function to display the queue*/
void show_ele()
{
struct q_point *ptr=NULL;
ptr=f_ptr;
if(e_que())
{
printf("ntQUEUE is Empty.");
return;
}
else
{
printf("ntElements present in Queue are:nt");
while(ptr!=NULL)
{
7. printf("%dt",ptr->ele);
ptr=ptr->n;
}
}
}
/* Write C programs that implement Queue (its operations) using i) Arrays */
#include<stdio.h>
#include<alloc.h>
#include<conio.h>
#define size 10
#define true 1
#define false 0
struct q_arr
{
int f,r;
int num;
int a[size];
};
8. void init(struct q_arr* queue);
int e_que(struct q_arr* queue);
int f_que(struct q_arr* queue);
int add_ele(struct q_arr* queue,int);
int rem_ele(struct q_arr* queue);
void display_ele(struct q_arr* queue);
/*main function*/
void main()
{
int ele,k;
int ch;
struct q_arr *queue = (struct q_arr*)malloc(sizeof(struct q_arr));
init(queue);
while(1)
{
clrscr();
printf("nn****IMPLEMENTATION OF QUEUE USING ARRAYS****n");
printf("============================================");
printf("nttMENUn");
printf("============================================");
printf("nt[1] To insert an element");
9. printf("nt[2] To remove an element");
printf("nt[3] To display all the elements");
printf("nt[4] Exit");
printf("nnt Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("nElement to be inserted:");
scanf("%d",&ele);
add_ele(queue,ele);
break;
}
case 2:
{
if(!e_que(queue))
{
k=rem_ele(queue);
printf("n%d element is removedn",k);
getch();
}
10. else
{
printf("tQueue is Empty. No element can be removed.");
getch();
}
break;
}
case 3:
{
display_ele(queue);
getch();
break;
}
case 4:
exit(0);
default:
printf("tInvalid Choice.");
getch();
break;
}
}
11. }
/*end main*/
void init(struct q_arr* queue)
{
queue->f = 0;
queue->r = -1;
queue->num = 0;
}
/* Function to check is the queue is empty*/
int e_que(struct q_arr* queue)
{
if(queue->num==0)
return true;
return false;
}
/* Function to check if the queue is full*/
int f_que(struct q_arr* queue)
{
if(queue->num == size)
return true;
return false;
12. }
/* Function to add an element to the queue*/
int add_ele(struct q_arr* queue,int j)
{
if(f_que(queue))
return false;
if(queue->r == size - 1)
queue->r = -1;
queue->a[++queue->r] = j;
queue->num++;
return true;
}
/* Function to remove an element of the queue*/
int rem_ele(struct q_arr* queue)
{
int j;
if(e_que(queue))
return -9999;
j = queue->a[queue->f++];
if(queue->f == size)
queue->f = 0;
13. queue->num--;
return j;
}
/* Function to display the queue*/
void display_ele(struct q_arr* queue)
{
int j;
if(e_que(queue))
{
printf("Queue is Empty. No records to display.");
return;
}
printf("nElements present in the Queue are: ");
for(j=queue->f;j<=queue->r;j++)
printf("%dt",queue->a[j]);
printf("n");
}