将数组转换为链表 [英] convert array to linked list

查看:363
本文介绍了将数组转换为链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我理解这个问题





考虑取得求职者学位的大学人力资源系统
并为它们分配ID(即顺序号)。



初始步骤:



(假设您每年只收到20个申请人)您的课程应该参加每个申请人的学位并将其存储在一个数组中。由于数组的索引代表申请人的ID,如下所示:index + 1 = ID

学位是(文凭,学士,硕士,博士,教授)。如果用户插入1则意味着教授学位等。



学位当量数

教授学位1

博士2

硕士3

学士4

文凭5



EX:第一申请人拥有硕士学位,第二个申请人有教授学位,第三个申请人有文凭学位......,所以阵列将是:



0 1 2

3 >
1 5 ...



主要步骤:



将数组转换为实施优先级队列使用排序顺序(使用链接列表来实现优先级队列)。

因为:值= ID(ID =数组索引+1)。

键=度(这意味着教授的优先级最高,然后是key = 1等等。

<在您的代码中,您必须逐个元素地逐个元素地将元素插入到具有排序序列(排队)的新优先级队列中。确保将元素插入适当的位置。

提示:如果两个条目具有相同的优先级(即具有相同的密钥),则在已经存在的条目之后插入具有相同键值的新条目entry。

please help me to understand this question


Consider university human resource system that take the degree of the job applicant
and assign an ID for them (i.e. Sequential number).

Initial Step:

(Suppose you only receive 20 applicant every year ) your program should take the degrees of each applicant and store it in an array. Since the index of array represents the ID of the applicant like the following: index+1=ID
The degrees are (Diploma, bachelor, master, PHD, Professor).If the user insert 1 it means professor degree and so on.

Degree Equivalent number
Professor Degree 1
PHD 2
Master 3
Bachelor 4
Diploma 5

EX: First applicant has Master degree ,second applicant has Professor degree, third applicant has Diploma degree…, so the array will be:

0 1 2
3
1 5 …

Main step:

convert the array to Implement Priority Queue with Sorted Sequence (use linked list to implement the Priority Queue).
Since : the value = ID (ID = array index +1 ) .
the key =Degree (it means professor has the highest priority then key=1 and so on).

in your code, you have to go element by element in the array and insert that element in your new Priority Queue with Sorted Sequence (enqueue) . be sure you insert the element in the appropriate position.
Hint: if two entries have the same priority ( i.e. have the same key) then the new entry with same key value will be inserted after the already existing entry.

推荐答案

您需要创建一个优先级队列(一个容器,其中元素具有优先级,因此存储在依赖于其数据的顺序中),并推送该容器中数组的元素。如果你插入代码中的正确位置,这意味着你并没有真正创建一个优先级队列,你使用链表并在你自己的代码中的正确位置插入元素,而不是容器代码。列表对此有好处,因为在列表中间插入并不昂贵(也就是说,它们很快)
You need to create a priority queue ( a container where elements have a priority and thus are stored in an order dependant on their data ), and push the elements of an array in to that container. If you''re inserting at the correct position in your code, that means you''re not really creating a priority queue, you''re using a linked list and inserting elements at the correct position in your own code, not in the container code. A list is good for this because inserts in the middle of a list are not expensive ( that is, they are quick )


这篇关于将数组转换为链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆