diff --git a/C++/LinkedListusingArrays.cpp b/C++/LinkedListusingArrays.cpp new file mode 100644 index 0000000..ee4fcce --- /dev/null +++ b/C++/LinkedListusingArrays.cpp @@ -0,0 +1,81 @@ + +#include +# define max 10 +using namespace std; +typedef struct Node{ + int data; + Node *next; +}Node; + class Stack{ + + int arr[max]; + int top; + public: + Stack(){ + top=-1; + } + bool isEmpty(); + bool isFull(); + void push(int ); + int pop(); + int size(); + void display(); +}; + +bool Stack::isEmpty(){ + if (top==-1){ + return true; + } + return false; +} +bool Stack::isFull(){ + if (top==max-1){ + return true; + } + return false; +} +void Stack ::push(int b ){ + if(isFull()){ + cout<<"Cannot enter as the stack is full"; + } + else{ + top++; + arr[top]=b; +}} +int Stack ::pop( ){ + if(isEmpty()){ + return 0; + }else{ + int x; + x=arr[top]; + top--; + return(x); + } +} +int Stack:: size(){ + int i; + for ( i=0;i<=top;i++); + return i; +} + +void Stack::display(){ + for (int i=0;i<=top;i++){ + cout< +using namespace std; +typedef struct Node{ + int data; + Node *next; +}Node; + class Stack{ + + Node *top; + public: + Stack(){ + top==NULL; + } + bool isEmpty(); + + void push(int x); + int pop(); + int size(); + void display(); + +}; + +bool Stack::isEmpty(){ + if (top==NULL){ + return true; + } + return false; +} +void Stack ::push(int b ){ + Node *newNode; + newNode = new Node; + newNode->data=b; + newNode->next=top; + top=newNode; + +} +int Stack ::pop( ){ + if(isEmpty()){ + return 0; + } + int y; + Node *temp; + temp=top; + top=top->next; + y=temp->data; + + delete temp; + return y; + +} +int Stack:: size(){ + int count=0; + Node *temp; + temp=top; + while(temp!=NULL){ + temp=temp->next; + count++; + + } + return count; +} + +void Stack::display(){ + Node *temp; + temp=top; + while(temp!=NULL){ + cout<data<<" "; + temp=temp->next; + } +} +int main() +{ + Stack s; + s.push(10); + s.push(20); + s.push(30); + s.push(40); + s.push(50); + s.display(); + cout<