NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io



#include <iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;

class Stack {//class with name Stack

int nitems;//private data members
int size;
char *beg;
char *end;
char *sp;

public: void setNitems(int nitems);
void setSize(int size);
void setBeg(char *beg);
void setEnd(char *end);
void setSp(char *sp);
void soi();

int getNitems();
int getSize();
char *getBeg();
char *getEnd();
char *getSp();


};


void Stack::setNitems(int nitems) {
this->nitems = nitems;
}


void Stack::setSize(int size) {
this->size = size;
}


void Stack::setBeg(char *beg) {
//cout << (int*) &beg[0]<<endl;
//this->beg =&beg[0];
this->beg = beg;
}


void Stack::setEnd(char *end) {

this->end = &end[nitems*size-size];
}


void Stack::setSp(char *sp) {
this->sp = sp;
//this->soi();

}

inline int Stack::getNitems()
{
return (this->nitems);
}

inline int Stack::getSize()
{
return (this->size);
}

inline char * Stack::getBeg()
{
return(this->beg);
}

inline char * Stack::getEnd()
{
return (this->end);
}

inline char * Stack::getSp()
{
return (this->sp);
}
inline void Stack::soi() {
cout << (int*)sp<<endl;
}


Stack *createStack(int nitems, int size)
{
Stack *newStack = new Stack();

char *array = new char[nitems*size];

newStack->setNitems(nitems);
//cout<<newStack->getNitems()<<endl;

newStack->setSize(size);
//cout << newStack->getSize() << endl;

//cout << (int*)&array[0]<<endl;
newStack->setBeg(&array[0]);
//cout << newStack->getBeg() << endl;
cout << (int*)&array[nitems*size - size] << endl;

newStack->setEnd(array);
//cout << newStack->getEnd() << endl;

newStack->setSp(&array[0]);
//cout << newStack->getSp() << endl;

return newStack;
}

void myMemcpy(char *destination, char *source, int size)
{

for (int i = 0; i < size; i++)
destination[i] = source[i];
}
int push(Stack * stack, char * item)
{
stack->soi();
cout << *(double*)item << endl;
if (stack->getSp() == stack->getEnd()) {
cout << "STACK OVERFLOW" << endl;
return -1;
}
myMemcpy(stack->getSp(), item, stack->getSize());
stack->setSp(stack->getSp() + stack->getSize());
stack->soi();

return 0;
}

int pop(Stack * stack, char * item)
{
stack->soi();
if (stack->getSp() == stack->getBeg()) {
printf("Empty Stackn");
return -1;
}
stack->setSp(stack->getSp() - stack->getSize());
stack->soi();

memcpy(item, stack->getSp(), stack->getSize());
stack->soi();
return 0;
}


































































/*#include <iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;

class Stack {//class with name Stack

int nitems;//private data members
int size;
char *beg;
char *end;
char *sp;

public: Stack *createStack(int nitems, int size);
int push(Stack *stack, char *item);
int pop(Stack *stack, char *item);
void closeStack(Stack *stack);

};

Stack * Stack::createStack(int nitems, int size)
{
Stack *newStack = new Stack();

char *array = new char[nitems*size];

newStack->nitems = nitems;

newStack->size = size;

newStack->beg = &array[0];

newStack->end = &array[nitems*size - size];

newStack->sp = &array[0];

return newStack;
}

void myMemcpy(char *destination,char *source,int size)
{

for (int i = 0; i < size; i++)
destination[i] = source[i];
}
int Stack::push(Stack * stack, char * item)
{
if (stack->sp == stack->end) {
cout << "STACK OVERFLOW" << endl;
return -1;
}
myMemcpy(stack->sp, item, stack->size);
stack->sp = stack->sp + stack->size ;
return 1;
}

int Stack::pop(Stack * stack, char * item)
{
stack->sp=(char *)((int *)stack->sp - ((stack->size) / 4));

memcpy(item, stack->sp, stack->size);
}*/

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.