• 欢迎访问废江's博客 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏本站吧

02-线性结构3 Reversing Linked List

浙大mooc 站点默认 1年前 (2019-11-04) 719次浏览 已收录 26个评论

Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.

Input Specification:
Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤10
​5
​​ ) which is the total number of nodes, and a positive K (≤N) which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Data Next
where Address is the position of the node, Data is an integer, and Next is the position of the next node.

Output Specification:
For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:
00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
Sample Output:
00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1

题意:给我们一组数据,第一组数据分别是头结点,组数,和翻转的值k。为什么要莫名其妙给我们一个头结点???划重点!随后,就是六祖数据,分别是结点地址,结点值,下一个结点的地址。翻转的意识是,头结点开始以k组数据为一组然后将这组数据翻转过来。值得注意的是,题目给我们的结点不是顺序的,需要我们后续把他们连起来,题意大概就是这么个题意了。

思路:先看看输出,简单利落,就是将翻转后的结点输出,当然前面是它自己的地址,后面是下一个结点的地址。我们首先想到的应该是用连链表的结构来做。但是要知道,我们的链表结构体的一个结点,在我们申请后就已经自动给我们分配了一个内存地址,这与题意的模拟地址不符,那我起码得扩充结构体申请三个数据位。但是这样做又是画蛇添足了。所以,只需要申请两个数组模拟链表就好了


个人博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:02-线性结构3 Reversing Linked List
喜欢 (2)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到
(26)个小伙伴在吐槽
  1. ingrediants in viagra viagra vs birth control insurance coverage mom gives son viagra
    匿名2021-03-03 01:02 (16小时前)回复 未知操作系统 | Firefox浏览器 40.1
  2. When some one searches for his required thing, therefore he/she desires to be available that in detail, therefore that thing is maintained over here.Feel free to visit my blog post; 10k Takipçi fiyatı
    匿名2021-02-28 21:09 (3天前)回复 Windows 10 | Chrome 60.0.3112.113
  3. cialis on line buy daily cialis from canada best cialis online
    匿名2021-02-27 21:44 (4天前)回复 未知操作系统 | Firefox浏览器 39.1
  4. Hello there, I found your blog by way of Google even as searching for a related subject, your website came up, it appears to be like great. I have bookmarked it in my google bookmarks.Hi there, simply was alert to your weblog through Google, and located that it's truly informative. I am gonna watch out for brussels.I'll appreciate in the event you continue this in future.Lots of other people shall be benefited out of your writing.Cheers!Feel free to surf to my blog: shell php
    匿名2021-02-23 15:45 回复 Windows 10 | Chrome 66.0.3359.170
  5. Hi, I do believe this is a great blog. I stumbledupon it ;) I may come back once again since I saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide other people.my site :: ucuz takipci satin al
    匿名2021-02-23 13:45 回复 Windows 10 | Chrome 66.0.3359.181
  6. Very smooth article free robux
    匿名2021-02-18 04:47 回复 Windows 10 | Chrome 83.0.4099.2
  7. cialis generique paris side effects taking cialis cialis 20 mg diario
    匿名2021-02-17 14:13 回复 未知操作系统 | Firefox浏览器 32.1
  8. bowling green ky cash advance planet green payday loans emirates nbd quick cash loan
    匿名2021-02-17 05:21 回复 Windows 10 | Firefox浏览器 57.0
  9. money mart loans review payday loans pace fl payday loan ut
    匿名2021-02-15 21:37 回复 Windows XP | Firefox浏览器 40.1
  10. does cialis cause leg cramps ervaring cialis once a day cialis receita medica portugal
    匿名2021-02-14 13:34 回复 未知操作系统 | Firefox浏览器 36.0
  11. unsecured cash loans other ways to get money besides loans advance auto loaner tools timing light
    匿名2021-02-13 10:54 回复 未知操作系统 | Firefox浏览器 43.1
  12. natchitoches payday loans online fast payday loan virus payday loan job seekers allowance
    匿名2021-02-12 07:40 回复 Windows 7 | Firefox浏览器 53.0
  13. buy real cialis generic cialis cheapest 800 mg cialis
    匿名2021-02-12 01:47 回复 Windows 7 | Chrome 61.0.3163.100
  14. buy viagra/denver,co buy generic viagra using mastercard herbal viagra gnc
    匿名2021-02-09 21:31 回复 Windows 10 | Chrome 61.0.3163.100
  15. board of pharmacy canada pharmacies without script best online canadian pharcharmy
    匿名2021-02-09 15:17 回复 Windows 10 | Chrome 63.0.3239.84
  16. Cialis Oral Jelly (Orange) online pharmacies in usa canadian king pharmacy
    匿名2021-02-07 16:48 回复 Windows 7 | Firefox浏览器 52.0
  17. discount cialis 20mg order original cialis online cialis on line
    匿名2021-02-06 16:01 回复 Windows 8.1 | Chrome 62.0.3202.94
  18. buy medication without an rx men's health viagra online canadian pharmacy
    匿名2021-02-05 06:24 回复 Windows 10 | Firefox浏览器 33.1
  19. is viagra covered by insurance viagra scams buy drugs online
    匿名2021-02-04 01:34 回复 Windows 10 | Firefox浏览器 57.0
  20. best drugstore eye cream cheapest pharmacy erectile dysfunction
    匿名2021-01-09 21:08 回复 Windows 7 | Firefox浏览器 52.0
  21. specialty pharmacy legit online pharmacy pharmacy coupons
    匿名2021-01-09 17:55 回复 Windows 7 | Chrome 62.0.3202.89
  22. canadian pharmacies erection pills online pharmacy reviews
    匿名2021-01-09 14:14 回复 Windows 7 | Firefox浏览器 57.0
  23. hello guos 9128738513
    匿名2021-01-05 21:45 回复 Windows 8.1 | Chrome 83.0.4103.44
  24. where to buy generic viagra viagra side effects blood pressure what works as good as viagra
    匿名2020-12-24 06:47 回复 未知操作系统 | Firefox浏览器 32.1
  25. 例子举错了,是比如100001→3→2→4→5
    匿名2020-04-28 19:40 回复 Windows 10 | Chrome 81.0.4044.122
  26. L类似1→2→3→...→N倒没有问题,但是如果没有顺序的规律呢?比如1→3→2→4→5
    匿名2020-04-28 19:35 回复 Windows 10 | Chrome 81.0.4044.122