PowerShell / PSReadLine

A bash inspired readline implementation for PowerShell
BSD 2-Clause "Simplified" License
3.72k stars 295 forks source link

Regarding creating the stack using aarays #3883

Closed swagger20 closed 10 months ago

swagger20 commented 10 months ago

Prerequisites

Exception report

Last 200 Keys:
 . \ s t a c k _ w i t h o u t _ u s i n g _ s t l Space } Enter   
 c d Space " c : \ U s e r s \ W i n \ O O P S Space C O N C E P T 
S \ c o m p l e x _ l i n k e d _ l i s t \ s t a c k \ " Space ; Space i f Space ( $ ? ) Space { Space g + + Space s t a c k _ w i t 
h o u t _ u s i n g _ s t l . c p p Space - o Space s t a c k _ w i t h o u t _ u s i n g _ s t l Space } Space ; Space i f Space ( $ 
? ) Space { Space . \ s t a c k _ w i t h o u t _ u s i n g _ s t l Space } Enter

Exception:
or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -1.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)      
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)        
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 
key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

Screenshot

![Capture](https://github.com/PowerShell/PSReadLine/assets/133804817/f6abdba0-3ee5-4bf6-a354-e447b03b9e4a)

Environment data

PS Version: 5.1.19041.3031
PS HostName: ConsoleHost
PSReadLine Version: 2.0.0-beta2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 174
BufferHeight: 24

Steps to reproduce

include

using namespace std; class Stack{ public: int top; int *arr; int size; Stack(int size){ arr=new int[size]; this->size=size; top= -1; } //functions void push(int data){ //2 scenarios: space available nd space not available i.e. if stack is already full or a empty space is there for insertion of an element if(size-top> 1){ //if space is available then top index is increased and in the array at that index new element will be inserted top++; arr[top]= data; } else{ //if space is not available cout<<"Stack overflow"<<endl; }

} void pop(){ if(top==-1){ //if stack is already empty, no element is there to remove cout<<"Stack Underflow"<<endl; } else{ //This will eventually point to the previous element of the already old pointed top just top-- will now point to the previous element it will give the index of that previous element top--; } } int getTop(){ if(top==-1){ cout<<"There is no elemet in the stack"<<endl; } else{ return arr[top]; } } int getsize(){ //This will give the no. of valid elements present in the stack top to inde ko bta hi rha hh to usme +1 kr do it will give you the total element sof the stack bcoz top hi apko last element ka index deta hh return top+1; } bool isempty(){ if(top==-1){ return 1; } else return 0; } }; int main(){ //stack creation we have to give the size of the array as in the constructor we have defined the paramter of size so size of array is passed of 10

Stack s(4); //insertion s.push(34); s.push(21); s.push(70); s.push(90); s.push(30); while(s.isempty()!=1){ cout<<s.getTop()<<" "; s.pop(); } cout<<endl; cout<<"Size of stack as all the elemnts are removed bcoz of popping them to get them printed:"<<s.getsize(); s.pop();

return 0; }

Expected behavior

NA

Actual behavior

NA

github-actions[bot] commented 10 months ago

@swagger20, you were using a pretty old version of PSReadLine (2.0.0-beta2 or prior), and it's likely that the issue was fixed in a newer version. Please upgrade to the 2.3.4 version of PSReadLine from PowerShell Gallery. See the upgrading section for instructions. Please let us know if you run into the same issue with the latest version.