did i code right?

The assigment was to get the stack of class couple that has number and appears, and im supposed to return a stack that has numbers from low at the bottom to high at the top, and each appear the number appear for that number, so for example for 1,2 0,3 it would return 0,0,0,1,1 did i write the code right? Does it work? How can i improve it, its probably too long
No description
No description
13 Replies
Buddy
Buddy2mo ago
$screenshot
MODiX
MODiX2mo ago
If you want to share code, please copy and paste the code into a markdown code block in your discord post, or paste the code into https://paste.mod.gg/ and share a link to it in your discord post. If want to share a screenshot, please do not take a photo of your computer screen with your phone or camera. Instead see https://www.take-a-screenshot.org/ for how to take a screen capture on your device. You may want to crop the image before pasting it into your discord message.
Buddy
Buddy2mo ago
Does what work? The code won't even compile, you have compilation errors
scuan🇮🇱
scuan🇮🇱2mo ago
Its because its given i have this class and dont need to create it and got a copy stack static i didnt create Also forgot to mention im using a package so everything with stack is the same but Top() is the same as pop but it doesnt remove only observes/retrieves . @Buddy, Citizen of Pluto 🔱 ok?
Buddy
Buddy2mo ago
$codegif
Buddy
Buddy2mo ago
But please use $paste
MODiX
MODiX2mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Buddy
Buddy2mo ago
That way it doesn't fill up the chat and people can see your original question
scuan🇮🇱
scuan🇮🇱2mo ago
Im on phone so its kind of hell to try that Black screen
public static Stack<int> eigtheen(Stack<Couple> ss)
{
Stack<Couple> sscopy2 = Copy(ss);//for order
Stack<Couple> sscopy3 = Copy(ss);


Stack<int> Order = new Stack<int>();//set order
Stack<Couple> extra = new Stack<Couple>();//set order


int minum = sscopy2.Top().GetNum();//set minum
int g = 0;//min spot
bool b = true;
while (!sscopy3.IsEmpty())
{
minum = sscopy2.Top().GetNum();//get first
while (!sscopy2.IsEmpty())
{


minum = Math.Min(minum, sscopy2.Pop().GetNum());//find the min num currently
}
Order.Push(minum);//push to the bottom the min num;
while (b)
{
if (sscopy3.Top().GetNum() == minum)
{
sscopy3.Pop();//remove the min in order
b = false;
}
else
{
extra.Push(sscopy3.Pop());//save it
}
}

b = true;
while (!extra.IsEmpty())//refill
{
sscopy3.Push(extra.Pop());
}
sscopy2 = Copy(sscopy3);//again but with new numbers

}

Stack<int> final = new Stack<int>();//the final to return
b = true;//making sure
sscopy2 = Copy(ss);//reuse

while (!Order.IsEmpty())//clear all orders
{
while (!sscopy2.IsEmpty() && b)
{
if (Order.Top() == sscopy2.Top().GetNum())

b = false;


else

sscopy2.Pop();

}
for (int i = 0; i < sscopy2.Top().GetAppears(); i++)
{
final.Push(Order.Top());
}
Order.Pop();
sscopy2 = Copy(ss);//get ready for next time
b = true;
}
return final;
}
public static Stack<int> eigtheen(Stack<Couple> ss)
{
Stack<Couple> sscopy2 = Copy(ss);//for order
Stack<Couple> sscopy3 = Copy(ss);


Stack<int> Order = new Stack<int>();//set order
Stack<Couple> extra = new Stack<Couple>();//set order


int minum = sscopy2.Top().GetNum();//set minum
int g = 0;//min spot
bool b = true;
while (!sscopy3.IsEmpty())
{
minum = sscopy2.Top().GetNum();//get first
while (!sscopy2.IsEmpty())
{


minum = Math.Min(minum, sscopy2.Pop().GetNum());//find the min num currently
}
Order.Push(minum);//push to the bottom the min num;
while (b)
{
if (sscopy3.Top().GetNum() == minum)
{
sscopy3.Pop();//remove the min in order
b = false;
}
else
{
extra.Push(sscopy3.Pop());//save it
}
}

b = true;
while (!extra.IsEmpty())//refill
{
sscopy3.Push(extra.Pop());
}
sscopy2 = Copy(sscopy3);//again but with new numbers

}

Stack<int> final = new Stack<int>();//the final to return
b = true;//making sure
sscopy2 = Copy(ss);//reuse

while (!Order.IsEmpty())//clear all orders
{
while (!sscopy2.IsEmpty() && b)
{
if (Order.Top() == sscopy2.Top().GetNum())

b = false;


else

sscopy2.Pop();

}
for (int i = 0; i < sscopy2.Top().GetAppears(); i++)
{
final.Push(Order.Top());
}
Order.Pop();
sscopy2 = Copy(ss);//get ready for next time
b = true;
}
return final;
}
Good ye?
MODiX
MODiX2mo ago
scuan🇮🇱
The assigment was to get the stack of class couple that has number and appears, and im supposed to return a stack that has numbers from low at the bottom to high at the top, and each appear the number appear for that number, so for example for 1,2 0,3 it would return 0,0,0,1,1 did i write the code right? Does it work? How can i improve it, its probably too long
Quoted by
<@203166497198047232> from #did i code right? (click here)
From scuan🇮🇱
React with ❌ to remove this embed.
scuan🇮🇱
scuan🇮🇱2mo ago
Also forgot to mention im using a package so everything with stack is the same but Top() is the same as pop but it doesnt remove only observes/retrieves Oh man.. was i supposed to post this in code review? @Buddy, Citizen of Pluto 🔱
Buddy
Buddy2mo ago
Might be a good category for this, yeah.
Want results from more Discord servers?
Add your server