Ho3in
Ho3in
CC#
Created by Ho3in on 3/8/2025 in #help
stack
The code I saw from my professor was like the one I sent, but it didn't use the class you mentioned, nor did it use these statics in the first variable, and it was a little simpler. You can
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
What is this? Is it a class?
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
The question given by the teacher is as follows: Question 1 Write a program that reads n integers from the input, then puts them on a stack, then clears the numbers in the stack and puts them on the output. By presenting Something like this but this seems to be used with a class or advanced, for example, statics before defining variables I don't want to be using System; class Program { static int[] stack; static int top = -1; static int n; // Push function to add an element to the stack static void Push(int k) { if (top < n - 1) { stack[++top] = k; } else { Console.WriteLine("The stack is full."); } } // Pop function to remove an element from the stack static int? Pop() { if (top == -1) { Console.WriteLine("The stack is empty."); return null; // Return null instead of throwing an error } return stack[top--]; } static void Main() { Console.WriteLine("Enter the number of numbers:"); n = int.Parse(Console.ReadLine()); stack = new int[n]; // Pushing numbers onto the stack for (int i = 0; i < n; i++) { Console.Write($"Enter number {i + 1}: "); int num = int.Parse(Console.ReadLine()); Push(num); } // Popping numbers from the stack and displaying them Console.WriteLine("Numbers popped from the stack:"); int? poppedNumber; while ((poppedNumber = Pop()) != null) { Console.WriteLine(poppedNumber); } } }
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
I haven't learned enough in class yet, so I needed a presentation.
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
im Persian iran
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
thanks
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
np
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
My teacher wrote with a presentation and said to start with a presentation.
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
No, the goal is this: I want to simulate the stack by presenting it as: int[] stack = new int[n];
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
Non, le but est le suivant : je veux simuler la pile en la présentant comme : int[] stack = new int[n];
46 replies
CC#
Created by Ho3in on 3/8/2025 in #help
stack
Not by presenting
46 replies