Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic stack using array and template #2

Merged
merged 19 commits into from
Oct 7, 2021
Merged

Conversation

redhawk2002
Copy link
Contributor

  • added README.md file containing Dynamic Stack content.
  • added dynamic_stacks_using_array_and_template.cpp file.
  • updated README.md file of Open-DSA.

@redhawk2002
Copy link
Contributor Author

@abxhr can you review this?

Comment on lines 1 to 6
# Dynamic stack using array
The idea of a dynamic stack is to allocate additional memory so that the "stack full" scenario does not occur frequently.
By allocating new memory that is bigger than the existing stack memory and copying elements from the old stack to the new stack, a Growable array-based Stack may be created. 
## Templates
The basic concept is to give the data type as a parameter, eliminating the need to write the same code for multiple data types. A software firm, for example, may require sort() for several data type. We can build a single sort() function and give data type as a parameter instead of creating and maintaining several codes.
## Operations
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a blank line after the ending of each section

Comment on lines 7 to 45

- size():

```
return nextIndex;
```

- checkEmpty():
```
return nextIndex==0;
```
- push(x):
```
if(nextIndex==capacity){
T *newdata=new T[capacity*2];
for(int i=0;i<capacity;i++){
newdata[i]=data[i];
}
capacity*=2;
delete []data;
data=newdata;
}
data[nextIndex]=element;
nextIndex++;
```
- pop():
```
if(checkEmpty()){
cout<<"stack is empty"<<endl;
return 0;
}
nextIndex--;
return data[nextIndex];

```
- top():
```
return data[nextIndex-1];

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • For the titles (eg: pop()), try to mention them through backticks, to format them better. Do this for all the function titles.
    eg:
`pop()`

is rendered as pop()

  • The code snippets are not indented well. Try to indent them from the left margin
  • The code snippet for top() is not closed.

Comment on lines 51 to 58
## Applications:

- expression evaluation.
- check parenthesis matching in an expression.
- Conversion from one form of expression to another.
- Memory Management.
- backtracking problems.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first character of each sentence is not capitalised.

@redhawk2002
Copy link
Contributor Author

@abxhr I have resolved the errors mentioned.
kindly review it.

@redhawk2002 redhawk2002 requested a review from abxhr October 7, 2021 06:11
@abxhr
Copy link
Owner

abxhr commented Oct 7, 2021

LGTM ✅
Thank you for your contribution! 💖

@abxhr abxhr merged commit 6cb38c0 into abxhr:main Oct 7, 2021
@abxhr abxhr linked an issue Oct 9, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hacktoberfest 2021! 🚀
2 participants