stack.c
#include<stdio.h>
#include<stdlib.h>
#include<limits.h> //INT_MIN
//structure for stack
struct stack
{
int top;
int capacity;
float *array;
};
//create a emptyp stack of size capacity
struct stack* createStack(int capacity)
{
struct stack* stk=(struct stack*)malloc(sizeof(struct stack));
stk->capacity=capacity;
stk->top=0;
stk->array=(float*)malloc(stk->capacity*sizeof(float));
return stk;
}
//check for stack is full or not
int isFull(struct stack *stk)
{
if(stk->top==(stk->capacity-1))
return 1;
return 0;
}
//check for stack is empty
int isEmpty(struct stack* stk)
{
return stk->top==0;
}
//push data to stack
void push(struct stack* stk,float data)
{
if(isFull(stk))
{
printf("\nstack is full");
return;
}
stk->array[++stk->top]=data;
printf("\n%.2f pushed to stack\n",data);
}
//pop data from stack
float pop(struct stack *stk)
{
if(isEmpty(stk))
{
printf("\nStack is empty");
return INT_MIN;
}
return stk->array[stk->top--];
}
int main()
{
struct stack* stk=createStack(1024);
push(stk,10.24);
push(stk,13.0);
push(stk,14.21);
printf("\n%.2f popped from stack\n",pop(stk));
push(stk,1.78);
push(stk,90.21);
printf("\n%.2f Popped from stack\n",pop(stk));
return 0;
}//end of main
OUTPUT

CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification:...
C
program
Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...
Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to Co Sci 839 or google: "binary...
Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...
program will enter data into two single dimension arrays (do not store duplicate values in arrays) program will find the union and intersection of the two arrays using one function program will find the symmetric difference of two arrays program will display the union, intersection, and symmetric difference */ short* input_data(short size); // function to dynamically allocate and array and enter data into the array void display_data(short *data, short size); // function to display data in an array void get_union_intersection(short...
Need help about C PROGRAMMING,, pls use only C LANGUAGE.., yea so
im doing this exercise as a practice for c programming, could
someone do this as well so i could compare if my code makes makes
sense and to see and help correct the errors im getting right
now..
Any helpful help would be appreciated..
Pointers &Pointer arithmetic Memory allocation and freeing Main topics: Exercise This lab is designed to give you practice working with pointers and memory allocation...
Purpose This assignment is an exercise in implementing the Stack ADT using a dynamically-allocated array, as well as techniques for managing dynamically-allocated storage in C++. Assignment In this assignment, you will write a class called Stack that will encapsulate a dynamically-allocated array of elements of a generic data type. A driver program is provided for this assignment to test your implementation. You don't have to write the tests. Program You will need to write a single template class for this...
Write a Client class with a main method that tests the data structures as follows: For the ArrayStack, LinkedStack, ArrayQueue and LinkedQueue: Perform a timing test for each of these data structures. Each timing test should measure in nanoseconds how long it takes to add N Integers to the structure and how long it takes to remove N Integers from the structure. N should vary from 10 to 100,000,000 increasing N by a factor of 10 for each test. Depending...
Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...