
//Stack.h
#pragma once
#include<stdio.h>
int push(double d); //– inserts the d onto the stack.Returns 1 if the insertion was successful, 0 otherwise.
double pop(void); //returns the double on the top of the stack and deletes it from the stack.Returns NaN if the stack is empty.
double peek(void); //returns the double on the top of the stack but does not delete it from the stack.Returns NaN if the stack is empty.
int isEmpty(void);//– returns 1 if the stack is empty, 0 otherwise.
int isFull(void); //– returns 1 if the stack is full, 0 otherwise.
int listStackContents(void);
-------------------------------------------
//Stack.c
#include"Stack.h"
#define NaN -1
//declare an array of 10 elements and top variable
double arr[10];
int top = 0;
int push(double d) //– inserts the d onto the stack.Returns 1 if the insertion was successful, 0 otherwise.
{
if (!isFull())
{
arr[top++]=d;
//return 1 to indicate successs
return 0;
}
else
{
return -1; //to indicate failure
}
}
double pop(void) //returns the double on the top of the stack and deletes it from the stack.Returns NaN if the stack is empty.
{
double ret;
if (!isEmpty())
{
//make old element -1 to indicate its delete
ret = arr[top - 1];
arr[top - 1] = -1;
--top;
return ret;
}
else
{
return NaN;
}
}
double peek(void) //returns the double on the top of the stack but does not delete it from the stack.Returns NaN if the stack is empty.
{
if(!isEmpty())
return arr[top - 1];
}
int isEmpty(void) //– returns 1 if the stack is empty, 0 otherwise.
{
if (top == 0)
return 1;
else
return 0;
}
int isFull(void) //– returns 1 if the stack is full, 0 otherwise.
{
if (top == 10)
return 1;
else
return 0;
}
int listStackContents(void)
{
int i;
printf("Content of stack are: ");
for (i = 0; i < top; i++)
{
printf("%.2f ", arr[i]);
}
printf("\n");
return 0;
}
----------------------------------------------------
//main to test stack
#include"Stack.h"
int main()
{
printf("%.2f (-1 indicates stack is empty)\n ",pop());
push(2.2);
push(3.3);
listStackContents();
printf("Top of stack is %.2f",peek());
pop();
printf("\nContents of stack after pop: \n");
listStackContents();
}
---------------------------------------
//output
-1.00 (-1 indicates stack is empty)
Content of stack are: 2.20 3.30
Top of stack is 3.30
Contents of stack after pop:
Content of stack are: 2.20
-------------------------------------
//Queue.h
printf("\nContents of Queue after pop: \n");
listStackContents();
-----------------------------------------------
//Queue.c
#include"Queue.h"
#define NaN -1
//declare an array of 10 elements and top variable
double arr[10];
int front = 0;
int rear=0;
int enqueue(double d) //– inserts the d onto the stack.Returns 1 if the insertion was successful, 0 otherwise.
{
if (!isFull())
{
arr[rear++]=d;
//return 1 to indicate successs
return 0;
}
else
{
return -1; //to indicate failure
}
}
double dequeue(void) //returns the double on the top of the stack and deletes it from the stack.Returns NaN if the stack is empty.
{
double ret;
int i;
if (!isEmpty())
{
//make old element -1 to indicate its delete
ret = arr[front];
//move elements from right to left
for(i = 0; i < rear-1; i++)
arr[i]=arr[i+1];
--rear;
return ret;
}
else
{
return NaN;
}
}
double peek(void) //returns the double on the top of the stack but does not delete it from the stack.Returns NaN if the stack is empty.
{
if(!isEmpty())
return arr[front ];
}
int isEmpty(void) //– returns 1 if the stack is empty, 0 otherwise.
{
if (front == rear)
return 1;
else
return 0;
}
int isFull(void) //– returns 1 if the stack is full, 0 otherwise.
{
if (rear == 10)
return 1;
else
return 0;
}
int listStackContents(void)
{
int i;
printf("Content of Queue are: ");
for (i = 0; i < rear; i++)
{
printf("%.2f ", arr[i]);
}
printf("\n");
return 0;
}
-------------------------------------------
//main to test queue
#include"Queue.h"
int main()
{
printf("%.2f (-1 indicates Queue is empty)\n ",dequeue());
enqueue(2.2);
enqueue(3.3);
enqueue(4.3);
enqueue(5.3);
enqueue(6.3);
listStackContents();
printf("Front of Queue is %.2f",peek());
dequeue();
printf("\nContents of Queue after pop: \n");
listStackContents();
dequeue();
printf("\nContents of Queue after pop: \n");
listStackContents();
}
/*output of Queue
-1.00 (-1 indicates Queue is empty)
Content of Queue are: 2.20 3.30 4.30 5.30 6.30
Front of Queue is 2.20
Contents of Queue after pop:
Content of Queue are: 3.30 4.30 5.30 6.30
Contents of Queue after pop:
Content of Queue are: 4.30 5.30 6.30
*/
Kindly help Asap....correct answers and numbering will be greatly appreciated.. thanks uestion 3 (50 In this...
Kindly help....use Github and gcc tool.....I always remember
to give a thumbs up to correct answers...help Asap
github.com Part 3 (15 pts) - Write a C source code module called insertionsort.c that performs an Insertion sort on a fixed size array. Provide a header file (insertionsort.h) so that your insertion sort function can be called from an external program. Define a symbol called IS_VERBOSE and use conditional compilation (#ifdef.#endif) to enable and disable reporting of diagnostic information as the sort...
Reverse Polish (HP) Style Calculator - Part 3 The purpose of this assignment is to build the business calculator using supporting files built in Topics 4 and 5. Create a Java application file named RPN.java containing a main method by using the ForthStack.java and associated files from Topic 5. The application should have one text box for numeric data entry, one text box for numeric display, one text box for error display, and buttons labeled "+", "-", "*", "/", "dup",...
Study the "Queue as linked list simple example" posted in this module. Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. LListQueue.cpp ///--------------------------------------------------------------- /// File: LListQueue.cpp /// Purpose: Implementation file for a demonstration of a queue /// implemented as an array. Data type: Character /// Programming Language: C++ ///--------------------------------------------------------------- #include "LListQueue.h" ///-------------------------------------------- /// Function: LListQueue() ///...
I need help fixing my code. My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...
1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...
Pease help ASAP C programming course. Cannot use global variables. This is the assignment: In this project you will calculate the maximum profit you could have made by trading a single stock over a period of one month. You will assume that you bought rounded stock units (usually in hundreds, or tens) worth between $3000 and $5000 at the best possible“closing” price during the period and sold it at the best possible “closing” price. You will assume that you are...
According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. A CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A company has text data that is not...
Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h (downloadable off the class web pages): #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const...
Write the C module intSet to implement an unordered set of integers according to the specification given below. File intSet.h: #ifndef INTSET_H #define INTSET_H typedef struct intsetType *intSet; intSet createSet(); // returns an intSet created at runtime using malloc void destroySet(intSet); // frees up the memory associated with its argument void clear(intSet); // clears set to empty (freeing any memory if necessary) int card(const intSet); // returns the cardinality of the set bool equals(const intSet,const intSet); // returns true if...
Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...