单链表头尾法?

时间:2018-10-24 18:44:37

标签: c data-structures

我对C编程语言还比较陌生,并且一直在玩耍以熟悉它,但是我不确定如何使用下面要尝试的结构和数据来实际实现链表。 )。基本上,目标是从带有头和尾的单链列表中添加一个项目。

更新:我试图在我的add函数中编写一些代码,但还没有对它进行排序,但这是什么样子?

代码源

<%=form_for(:search_results, url:{controller: :search_results, action: :index}, html:{id:"quickSearch"}) do | f| %>
...form fields...
<% end %>

1 个答案:

答案 0 :(得分:-1)

首先,正确定义您的结构。

SELECT person, COUNT(*)
FROM (
    SELECT * FROM table
    ALL LEFT JOIN table
    USING variant
)
GROUP BY person
HAVING COUNT(*) == 1;

现在,您尝试使用插入作为插入排序技术。

typedef struct car{
char car_model[32],car_name[32];
};

typedef struct myList{
myList * next;
car * carObject;
};

现在,您需要两个功能

void insertElementByTitle(MyList* someList, CarObjects* someCar){
\\I assume someList is pointing the head of the linked list
\\One more assumption that, the Linked List is already sorted and need to inset
\\someCar in the correct position.
MyList *secondPointer = someList->next;
while(secondPointer != null)
{
     if(ifCarIsInBetweenSomeListAndSecondPointer(someList,secondPointer,someCar))
     {
      someList->next = newNode(someCar);
      someList->next->next=secondPointer;
      break;
     }
  someList = secondPointer; secondPointer = secondPointer->next;
}
if(secondPointer == null)
{
     someList->next = newNode(someCar);
}
}

请参考在线参考文献,例如geeksforgeeks-linked list,以获得更好的理解。