I'm a noob at C++ (I learned it at school, so, yeah...) and I've got to make a program, which I find pretty difficult. i'm coming here seeking your help because I NEED a good grade if I want to validate my semester, and programming is highly coefficiented, so if you don't help me, i'm pretty much fucked...
So here's the deal:
Make a program which allows the input of a serie of integers and stocks them in a table, then display the table as it is and then display the table with the numbers sorted out in growing order...
I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.
So your help would be really, really, REALLY appreciated...
Pretty please?
Name:
Anonymous2007-11-28 10:45
int main(void)
{
// Initialize a (list|table) here
// Loop input collection function here
// Append input to list or break loop if no more input
// ::sort
// Iterate through list and print to stdout
return 0;
}
Fill in the blanks
Name:
Anonymous2007-11-28 10:46
>>2
Oh thank you that was soooooooooooooooooooooo helpful...
Name:
Anonymous2007-11-28 10:49
Look, I know I'm being a dick, but I really need a good grade!
The problem is that I have no fucking clue about how to sort the numbers in growing order (if that wasn't clear enough), so I don't know if you thought you were helping, but, well, you weren't.
>>7
I understand your logic, but I want to understand how C++ works, and that was the first reason why I came here, so you could help me understand it better, thus making me able to write the program I need.
>>19
yup, still haven't solved my problem (link provided by >>16 was helpful, but I can't use it, because we're supposed to use for, while, if and table only (sorry I didn't mention it firsthand)).
So, me and my friend are still working on it.
Name:
Anonymous2007-11-28 16:14
Look, I really need some help to get a good grade. If I don't my parents will beat me again.
Name:
Anonymous2007-11-28 16:31
>>21
That's why we read SICP and learn to program on our own.
Name:
Anonymous2007-11-28 16:34
What's the problem here? Just write a trivial bubble sort and be done with it.
>>24
You have two minutes to write a correct implementation of a sorting algorithm. If you fail, you will be brutally gangraped and then killed. YOUR CHOICE?
>>23
The problem obviously is that I have no idea about how to sort the numbers... (I'm STILL working on it btw, but still, no idea (ones I had didn't work))
Name:
Anonymous2007-11-28 16:45
Just use Monads and lambda haskell over closed manifolds.
Name:
Anonymous2007-11-28 16:48
>>27
As if I had a clue of what you're talking about
Name:
Anonymous2007-11-28 16:48
Why not just use arrays to put the variables in.
And then sort them into another array?
ITT people who prefer bubble sort because they are afraid of full recursion.
Name:
Anonymous2007-11-28 16:58
Well, it's 23:00 where i live (that is to say in france), so i'm going to bed nao, but, remember this, I WILL BE BACK! tomorrow to be exact, I will poast the answer our teacher gave us, and submit it to your judgment.
Thanks to all of you who sincerely tried to help me, I will bump this thread tomorrow (if it still exists) otherwise I will just make another one.
>>1
If I were you I wouldn't insult >>2, the answer he gave you was very helpful. Now, stop being brain-atrophied and learn how to think by yourself.
I am a total noob at C (as I already mentioned) and I have no fucking clue about how to do this kind of shit.
DA TEACHAR DIDN TEL ME HOW 2 DU DIS BUT I NO TEH TEORI TO LURN BY MYSELF OW 2 DO IT
how to sort arrays in a simple way for retarded dumbfucks :
Make an other array(newarray)
Get the biggest value of the array
in a loop in which i is the count, starts at 0 and stops when i is not smaller than the length of the array
{
Get the smallest value of the array and put it in newarray[i] then set array[i] to a bigger value than the biggest one
}
and return the new array
>>35
by table I meant 'un tableau' that is, something like a list or a table in which you can put numbers and stuff
Name:
Anonymous2007-11-28 17:19
Learn to fucking indent, I'll check it then.
Name:
Anonymous2007-11-28 17:24
>>41
I apologize to >>2, if I seemed rude (I probably was) it was only because I had a shitty day, blablabla personal life you don't care about. I know, I overreacted, and again, I apologize humbly.
Then, I don't know what arrays are (maybe they are what i call table, that would be horrible, but as I don't know the exact terms it is possible)
Holy shit, I just understood your post, for serious...
I'm baffled... O_O;;
Name:
Anonymous2007-11-28 17:32
Oh well, I'm off to bed, I can't even think clearly anymore.
print_list( list );
std::cout << std::endl;
std::sort( list.begin(), list.end() );
print_list( list );
}
Name:
Anonymous2007-11-28 19:22
HHAHAHA I LOVE THIS FRENCHY GUY ~♀~
Name:
Anonymous2007-11-28 19:43
>>48
"yup, still haven't solved my problem (link provided by >>16 was helpful, but I can't use it, because we're supposed to use for, while, if and table [i.e. arrays] only (sorry I didn't mention it firsthand))."
Name:
Anonymous2007-11-28 20:01
class Class {
public static void main(String[] args) {
ArrayList<Integer> a = new ArrayList<Integer>(1000);
for (i : a) {
i.add(Math.random() * Integer.MAX_VALUE);
}
System.out.println(a);
mergesort(a);
System.out.println(a);
}
//The rest of this code isn't even mine
public static ArrayList<Integer> mergesort(ArrayList<Integer> numbers) {
if (numbers.size() <= 1)
return numbers;
int middle = numbers.size() / 2;
ArrayList<Integer> left = new ArrayList<Integer>();
ArrayList<Integer> right = new ArrayList<Integer>();
for (int i = 0; i < middle; i++)
left.add(numbers.get(i));
for (int i = middle; i < numbers.size(); i++)
right.add(numbers.get(i));
left = mergesort(left);
right = mergesort(right);
return merge(left,right);
}
public static ArrayList<Integer> merge(
ArrayList<Integer> left, ArrayList<Integer> right) {
ArrayList<Integer> result = new ArrayList<Integer>();
while (left.size() > 0 && right.size() > 0) {
if (left.get(0) < right.get(0)) {
result.add(left.get(0));
left.remove(0);
} else {
result.add(right.get(0));
right.remove(0);
}
}
if (left.size() > 0) {
for (int i = 0; i < left.size(); i++)
result.add(left.get(i));
}
if (right.size() > 0) {
for (int i = 0; i < right.size(); i++)
result.add(right.get(i));
}
return result;
}
}
>>56
I know they don't, it simply is easier that way. I told you I am not an advanced coder.
>>57
Thank you. Do you see any way in which it could be improved? (I'm sure you do, however, I understand if you don't care enough to post it and just let the thread die.
>>55 >>56 said it. Your code is broken. Otherwise, not bad. Separate the sorting part to a function, though.
Name:
Anonymous2007-11-29 13:12
>>59
We're going to see functions next week actually
Name:
Anonymous2007-11-29 13:15
>>60
Wow, they are deliberately TEACHING you to write spaghetti code from early on?
Name:
Anonymous2007-11-29 13:20
>>61
Well, yes they are. What i wrote in >>55 was the best code we ever wrote, but then again, I'm not in a programming school, it's just part of my cursus, and there is 90% chance that I won't use it when I leave the institute.