학교 실험실의 경우 연결된 메일 목록을 만든 다음 해당 메시지를 우선 순위별로 정렬해야합니다. 우선 순위가 "높음"우선 순위에서 먼저 추출한 다음 보통, 낮음 순으로 정렬해야합니다. 나는 이것을 며칠 동안 알아 내려고 노력해 왔으며 나는 그 소팅에 대해 내 마음을 감쌀 수 없다. 나는 그것을 ListofMessages 클래스의 head와 size 필드 이외의 것을 추가하지 않고서 정렬하려고 노력했지만, 쓰레기 코드를 추가하는 것으로 보인다. 나는 이것을 스스로 이해하고 싶었지만 지금 당황 스럽다.개체의 정렬 가능한 연결 목록
여기까지 제가 지금까지 가지고 있습니다. 일부 정제 그러나 대부분의 작업은 현재 추가 기능에있다가 필요할 수 있습니다 메시지를 검색 할 수
class ListOfMessages
{
private int m_nSize;
public Message m_cListStart;
//public Message m_cNextItem;
public Message m_cLastItem;
public ListOfMessages()
{
m_nSize = 0;
m_cListStart = null;
//m_cNextItem = null;
}
public int Count
{
get { return m_nSize; }
}
public string Display(Message cMessage)
{
return "Message: " + cMessage.m_strMessage + "\nPriority: " + cMessage.m_strPriority;
}
//list additions
public int Add(Message newMessage)
{
Message nextMessage = new Message();
//inserts objects at the end of the list
if (m_nSize == 0)
{
m_cListStart = newMessage;
//m_cLastItem = newMessage;
}
else
{
Message CurrentMessage = m_cListStart;
if (newMessage.m_strPriority == "High")
{
if (m_cListStart.m_strPriority != "High")
{
//Make the object at the start of the list point to itself
CurrentMessage.m_cNext = m_cListStart;
//Replace the object at the start of the list with the new message
m_cListStart = newMessage;
}
else
{
Message LastMessage = null;
for (int iii = 0; iii < m_nSize; iii++)//(newmessage.m_strpriority == iii.m_strpriority)
//&& (iii.m_cnext == null);)
{
if (m_cListStart.m_strPriority != "High")
{
nextMessage = newMessage;
nextMessage.m_cNext =
CurrentMessage = nextMessage;
//LastMessage.m_cNext = CurrentMessage;
}
LastMessage = CurrentMessage;
if (m_cListStart.m_cNext != null)
m_cListStart = m_cListStart.m_cNext;
}
}
//iii = iii.m_cnext;
}
// for (int iii = m_cListStart; ; iii = iii.m_cNext)//(newMessage.m_strPriority == iii.m_strPriority)
// //&& (iii.m_cNext == null);)
//{
// //Message lastMessage = iii;
// if (iii.m_strPriority != iii.m_strPriority)
// {
// //iii.m_cNext = newMessage;
// newMessage.m_cNext = iii.m_cNext;
// iii.m_cNext = newMessage;
// }
//m_cLastItem.m_cNext = newMessage;
}
//m_cLastItem = newMessage;
return m_nSize++;
}
public Message Pop()
{
//Message Current = m_cListStart;
//if the object at the start of the list has another object after it, make that object the start of the list
//and decrease the size by 1 after popping an object off if there is more than 1 object after the start of the list
if (m_cListStart.m_cNext != null)
{
m_cListStart = m_cListStart.m_cNext;
}
if (m_nSize > 0)
m_nSize--;
else
m_cListStart = null;
return m_cListStart;
//if (m_cListStart.m_cNext != null)
// m_cListStart = m_cListStart.m_cNext;
//if (m_nSize > 1)
// m_nSize--;
//return m_cListStart;
}
내 팝업 기능 : 희망 당신은 그것을 이해 할 수 있습니다. 나는 정말로 거기서 어둠을 헤쳐 나가고있다.
누구든지 내가 원하는 것을하는 간단한 방법을 알고 있습니까? 다음과 같이
나는 왜곡 된 코드를 버리겠다. – Greener
당신은 그 코드로 고문을 당할 것입니다. 먼저 연결리스트가 어떻게 작동하는지 이해하고 몇 가지 코드 샘플을보십시오. – DarthVader
고려해야 할 또 다른 사항은 목록을 주로 요소를 삽입하는 데 사용하는지, 단일 정렬을 누른 다음 요소를 제거할지 여부입니다. 삽입 및 제거가 혼합 될 수도 있습니다. 혼합 될 경우 정렬 순서에 따라 요소를 삽입하여 정렬 된 목록을 그대로 유지할 수 있습니다. 또한 목록이 항상 정렬되므로 정렬을 구현하지 않아도됩니다. – R0MANARMY