hw5
Data Structure:
in C language:
#include <limits.h> #include <stdio.h> #include <stdlib.h> struct Stack { int top; unsigned capacity; int* array; }; struct Stack* createStack(unsigned capacity) { struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack)); stack->capacity = capacity; stack->top = -1; stack->array = (int*)malloc(stack->capacity * sizeof(int)); return stack; } int isFull(struct Stack* stack) { return stack->top == stack->capacity - 1; } int isEmpty(struct Stack* stack) { return stack->top == -1; } void push(struct Stack* stack, int item) { if (isFull(stack)) return; stack->array[++stack->top] = item; // printf("%d pushed to stack\n", item); } int pop(struct Stack* stack) { if (isEmpty(stack)) return INT_MIN; return stack->array[stack->top--]; } int peek(struct Stack* stack) { if (isEmpty(stack)) return INT_MIN; return stack->array[stack->top]; } int main() { int n; printf("How many elements?"); scanf("%d",&n); struct Stack* stack1 = createStack(n); struct Stack* stack2 = createStack(n); int arr[n]; printf("Enter the elements"); int i,j; for( i=0;i<n;++i) scanf("%d",&arr[i]); for( i=0;i<n;++i) { int flag=0; for( j=i+1;j<n;++j) { if(arr[j]>arr[i]) { push(stack1,arr[j]); flag=1; break; } } if(flag==0) push(stack1,-1); } for( i=0;i<n;++i) push(stack2,pop(stack1)); for( i=0;i<n;++i) { printf("%d ",arr[i]); int k=pop(stack2); if(k==-1) printf("none\n"); else printf("%d\n",k); } }
hw5 Data Structure: in C language: 2. Assuming that there is a series of int type...
In the problems below, give the order of the element in the indicated factor group. (a) in (b) in (c) in (5)(20 points) In the problems below, give the order of the element in the indicated factor group. (a) (1, 2)+ < (1,1) > in Z3 x Z6/ < (1,1) >. (b) (3, 2)+ < (4,4) > in Z6 * Z8/ < (4,4) >. (c) 26+ < 12 > in Z60/ <12>.
In C language 1. Write a program to declare and initialize an array of size 5 and place odd numbers 3, 5, 7,9 and 11 in it. Declare and initialize another array of size 5 and place even numbers 4, 6, 8, 10 and 12 in it. Write a for loop to add each element and place it in a third array of the same dimensions. Display each array.
1. What is the output of the following program? include <stdio.h> int wilma (int x) if (x<5) x = 7; return (x) int main (void) int x-1 x=wilma (x) ; printf ("%d", x); return (0) b)3 c) 4 d) 7 a) 1 e) none of these
Please Answer this question using the language of C++. I provide you with the picture of figure 18_02. Thank you. I 7/ Fig. 18.2: Stack.h 2 // Stack class template. #ifndef #de fine 3 STACK-H STACK-H 5 #include 7 template 8 class Stack ( 9 public: 10 I const T& top) 12 13 l/ return the top element of the Stack return stack.frontO; // push an element onto the Stack void push(const T& pushValue) 15 stack push front (pushValue); 17...
Write the parametric equations x=2siny=4cos0 in the given Cartesian form. y^2/16= with x0. Write the parametric equations x=2sin2y=5cos2 in the given Catesian form. y= with 0x2. Write the parametric equations x=4ety=8e−t as a function of x in Cartesian form. y= with x0. Write the parametric equations x = 2 sin 0, y = 4 cos 0, 0<O< in the given Cartesian form. = with x > 0. 16 Write the parametric equations x = 2 sin’e, y = 5 cos?...
1) 2) 3) integer A, B; input (A): while (A> 0) 5) A=2*A; 6) i (A < 20 or A> 30) 7) 8) 9) 10 lse B-A 2, 12) B-A 2 13) 14) output (A, B): 15) input (A): 16) end;
In C programming Language Write a version of the infix-to-postfix conversion algorithm. Write a program that converts an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers For Example: Infix expression (6 + 2) * 5 - 8 / 4 to a postfix expression is 62+5*84/- The program should read the expression into character array infix and use the stack functions implemented in this chapter to help create the postfix expression in character array postfix. The...
c language not c++ c language int mininum(int a[135) int i; int min. Question 2 (4 points) If ptr is an integer pointer and x in an integer variable then write one statement to set ptr to point to x then write another statement to increment x by 10 using ptr (not using x) (4 points) Question 3 (4 points) Saved
C Programming Language The operation of multiplication for positive integers can be expressed as: A.B=2 1 A for (A+[A.(B-1)] B=1 for B>1 Task 1 (for 1 point) is to write a program that will read and print on the screen the values of two integers (A and B) given by user as command line parameters. Task 2 (for 1 point) is to write a program that will calculate the result of the multiplication of two integers. It should print...
Write MARIE assembly language programs that do the following: I. Write a program that inputs three integers, a, b, and c, in that order. It computes the following ia-bi-fc+ c The result should be written to output 2. Write a program that inputs integers, s. y, and z. It outputs the difference of the langest and first element entered. You may assume x. y, and z all have different values. So if 8, 12, and 9 are input, the output...