Topic: 求救!在线等!(用单链表比较两个文件,并按要求输出结果)

  Print this page

1.求救!在线等!(用单链表比较两个文件,并按要求输出结果) Copy to clipboard
Posted by: cserbaby
Posted on: 2005-08-30 08:09

请尽量使用准确的文字描述作为标题
Your next post without a proper Subject will be removed.



救命啊,小弟这道题到现在还没有什么思路,哪位大哥能指点下?不胜感激!
先谢过了!

比较A。TXT和B.txt文件有什么不同!例如:若A.txt的内容为:b c a d
B.txt的内容为:a c d b ,则输出结果为:
A.txt B TYPE
________________________
b - Del
c - Del
a a ok
- c Add
d d ok
- b add
若A.txt中的内容为:a c d b,B.txt中的内容为:b c a d,则输出结果为:
A.txt B TYPE
________________________
- b Add
- c Add
a a ok
c - Del
d d ok
b - Del
要求用单链表实现!(用别的方法也行!)
(所求救的是如何显示这样的结果!)

2.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: cserbaby
Posted on: 2005-08-30 19:38

啊 ,怎么还没有人回啊!

救命啊,

没源程序没有关系的啊

只要说下思路也行啊!

3.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: why
Posted on: 2005-08-30 20:38

題目不是說 "用单链表实现" 嗎?
很坦白說,敝人看不出這道題還需要甚麼思路,anyway...

I believe that if you have tried to learn how to do the following in Java, you're almost done:
1. how to read (a String) from a file.

2. how to create and use a 单链表 -- is it singly-link list?
2a. of course you could create your own link list implementation, but you may also use java.util.LinkedList or java.util.ArrayList
http://java.sun.com/docs/books/tutorial/collections/implementations/list.html
2b. how to use an Iterator to walk through the list

3. how to do String comparison and print the required table

Well, what's left is the implmentation of the logic descirbed in your question -- using a bunch of "if"s within a big "while" loop
but, frankly, who'd care to read such assignment nonsense,
you have to do your homework, man.
天助自助者

4.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: cserbaby
Posted on: 2005-08-30 21:14

谢过WHY!
单链表我自己已经写好了,那个TXT进链我 也已经实现,现在的问题是怎么判断A和B的的值,才可使得输出那些结果,要求是A和B的输出顺序要和原来的是一样的!(就像您看的的一们)这个流程是什么样的?

5.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: why
Posted on: 2005-08-30 22:14

cserbaby wrote:
单链表我自己已经写好了,那个TXT进链我 也已经实现,现在的问题是怎么判断A和B的的值,才可使得输出那些结果,要求是A和B的输出顺序要和原来的是一样的!(就像您看的的一们)这个流程是什么样的?

真是豈有此理,為甚麼不在問問題時說淸楚!!!

很坦白說,敝人是十二分不願意看那個表...
敝人猜的是:如何將A的內容變成B的內容
A.txt的内容为:b c a d
B.txt的内容为:a c d b
则输出结果为:
b - Del // B.curr : a, A.curr : b, A.curr ranks higher, Del, A.next
c - Del // ...
a a ok // B.curr = A.curr, ok, A.next, B.next (*)
- c Add // B.curr != A.curr. Add, B.next (#)
d d ok // same as step * above
// A is done
- b add // same as step # above
// B is done

若A.txt中的内容为:a c d b,
B.txt中的内容为:b c a d,
则输出结果为:
- b Add // B.curr ranks higher, Add, B.next
- c Add // ...
a a ok // same as step * above
c - Del // Del A, A.next
d d ok // same as step * above
// B is done
b - Del // Del A, A.next
// A is done

"ranks higher" is just an assumption, it could be some other criteria, say, "starts with a".
We couldn't tell while the information provided is too limited.

6.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: cserbaby
Posted on: 2005-08-30 23:11

非常感谢WHY这么晚还回复我的帖子

不过你说的这个方法我也想过,好像不行啊!
b - Del // B.curr : a, A.curr : b, A.curr ranks higher, Del, A.next(第一种输出结果)
- b Add // B.curr ranks higher, Add, B.next(第二种输出结果)

这儿的ranks higher不知道如何判断?(在我看来是有矛盾的,一个是Del,另一个是Add)

对我没有说清楚问题我现在只能说声sorry!

7.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: why
Posted on: 2005-08-30 23:39

cserbaby wrote:
非常感谢WHY这么晚还回复我的帖子

不过你说的这个方法我也想过,好像不行啊!
b - Del // B.curr : a, A.curr : b, A.curr ranks higher, Del, A.next(第一种输出结果)
- b Add // B.curr ranks higher, Add, B.next(第二种输出结果)

这儿的ranks higher不知道如何判断?(在我看来是有矛盾的,一个是Del,另一个是Add)

It's 11am Eastern Standard Time
判断 "ranks higher"? "b" > "a", as simple as that.
You should ask the one who made up this question whether this is what s/he expected.

There is not enough information to determine. Is this clear?

8.Re:求救!在线等!(一道题求思路 用单链表) [Re: why] Copy to clipboard
Posted by: cserbaby
Posted on: 2005-08-31 09:53

why wrote:
It's 11am Eastern Standard Time
判断 "ranks higher"? "b" > "a", as simple as that.
You should ask the one who made up this question whether this is what s/he expected.

There is not enough information to determine. Is this clear?

这是我的一道笔试题,我也没有得到太多的信息,我自己到现在也是不晓得他要问的是什么,题目上只是说:用户有一个文件A.txt,在修改后变成了文件B.txt
现在他想知道A.txt和B.txt现文件到底有什么不同,要求输出结果就是上面我写的

9.Re:求救!在线等!(一道题求思路 用单链表) [Re: cserbaby] Copy to clipboard
Posted by: why
Posted on: 2005-08-31 11:51

cserbaby wrote:
这是我的一道笔试题,我也没有得到太多的信息,我自己到现在也是不晓得他要问的是什么,题目上只是说:用户有一个文件A.txt,在修改后变成了文件B.txt
现在他想知道A.txt和B.txt现文件到底有什么不同,要求输出结果就是上面我写的

Then you could just make your own assumption, educated guess.

10.Re:求救!在线等!(用单链表比较两个文件,并按要求输出结果) [Re: cserbaby] Copy to clipboard
Posted by: wonderfuture
Posted on: 2005-09-01 07:50

这个逻辑好不容易才看懂:
首先,A表B表指针位于首位
1-取B表当前元素,与A表当前元素相比:若B的大,将B的元素加入C表,显示"<B的元素>-Added",接着B表指针后移;若A的大,将B的元素加入C表(但不能在后续步骤中重复添加),显示"<A的元素>-Del",接着A表指针后移;若两元素相等,将元素加入C表,显示"<该元素>-OK",两表指针同时后移,这种情况后续算法必需进行"翻转"(即当A的大,A表位置不变,添加B表元素并移动B表指针,当A的小删除并后移A指针)
2-重复上述算法,并注意当B表先到达末尾要删除A的剩余元素,当A先到达末尾要添加B的剩余元素

11.Re:求救!在线等!(用单链表比较两个文件,并按要求输出结果) [Re: cserbaby] Copy to clipboard
Posted by: cserbaby
Posted on: 2005-09-06 22:46

好久没来了,谢谢wonderfuture


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923