作者richardl003 (飞行岩)
看板C_and_CPP
标题Re: [问题] 搞不清楚要做什麽
时间Wed Feb 18 14:42:18 2009
※ 引述《MOONRAKER (㊣快使用弯曲速度,舰长!)》之铭言:
: ※ 引述《richardl003 (飞行岩)》之铭言:
经过这位大大的解释
我独自参考书写了几天
终於写了以下的程式码
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
class node{
public:
node *last;
int data;
int order;
node *next;
private:
};
int main( int a, char * b[] ) {
int i;
srand((unsigned)time(0));
node *head, *tmp0, *tmp1, *end;
head = new node;
head->last = NULL;
head->next = NULL;
head->order=0;
head->data = rand()%atoi(b[2]);
tmp0 = head;
for (int i=1; i<atoi(b[1]); i++) {
tmp1 = new node;
tmp1->last = tmp0;
tmp1->next = NULL;
tmp1->data = rand()%atoi(b[2]);
tmp1->order=i;
tmp0->next = tmp1;
tmp0 = tmp1;
}
end = tmp1;
tmp0 = head;
while (tmp0 != NULL) {
cout << tmp0->data << ',';
tmp0 = tmp0->next;
}
cout << endl;
tmp0 = end;
while (tmp0 != NULL) {
cout << tmp0->data << ',';
tmp0 = tmp0->last;
}
cout << endl;
tmp0 = head;
while (tmp0 != NULL) {
if(tmp0->order==6)cout<<"31337,";
cout << tmp0->data << ',';
tmp0 = tmp0->next;
}
cout << endl;
system("pause");
}
可是老师把我的程式退了回来
说我没有达成他题目的要求
可是我明明都有跑出来了
请问大家我错在哪里
: : 这是我们第一次的作业
: : 但我看也看不懂
: : 再这个版爬文爬了很九
: : 但是还是不知道该怎麽做
: : 请问我该买什麽书来看吗
: : 或是可以用中文跟我说这是什麽样的观念吗
: : 该做什麽事
: : 我用字典把每个字查了还是不知道该怎麽做
: : Implements a doubly-linked list – that’s a linked list which is linked
: : backward and forward
: 做一个双向连结串列;也就是串列里面每一个元素都是狡猾的元素,
: 先向後连再向前连(骗你的)。
: : Populates it with X random integer values, between 0 and MAX in value, where
: : X and MAX are taken from the command line:
: : “dblprog 20 40” would create a linked list with 20 random values in the
: : range 0-40.
: 然後在此串列中塞进 X 个值域 [ 0, MAX ] 的乱数,其中 X 和 MAX 可以用以下
: 的格式在命令列输入:
: "dblprog 20 40" 就是产生 20 个值域为 [ 0, 40 ] 的乱数放进串列里。
: : Prints the list out forwards and then in reverse
: : Demonstrates inserting a value 31337 in position 7, and printing the list
: : again
: 首先正着印出串列,然後倒过来再印一次。(我这把枪是狡猾的枪…)
: 把数值 31337 插入到位置 7 的地方,再印一次串列。
: : You must use a class for this!
: 注意:以上的一切功能都要写成 class!
: : Program should be a command line program in Visual C++ 2008
: : Just submit the .cpp and .h files. Don’t select “precompiled headers” when
: : you build please.
: : Please name your project “dblprog” – that way, we can grade just by
: : cutting and pasting
: 程式要用 Visual C++ 2008 写成命令列程式。只要交 .cpp 和 .h 就好了。拜托
: 在建置的时候(或者开专案的时候?)不要选"precompiled headers"选项。
: 请把程式命名为 dblprog ,这样我们评分比较方便。
:
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.115.50.10
1F:推 untitle:大概是希望你把要求的功能写成member functions吧 02/18 15:39
2F:推 LawlietDo:You must use a class for this! 02/18 18:46
3F:→ MOONRAKER:你只有node写成class,你老师是希望你写一个list的class 02/18 22:05
4F:→ MOONRAKER:里面要包node class,而且在class里面就要有add print 02/18 22:06
5F:→ MOONRAKER:print_reverse add_at等等功能 所以你被退啦 XD 02/18 22:07