<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 按數組中出現的元素順序對鏈接列表進行排序 > 原文: [https://www.geeksforgeeks.org/sort-linked-list-order-elements-appearing-array/](https://www.geeksforgeeks.org/sort-linked-list-order-elements-appearing-array/) 給定一個大小為 N 的數組和一個鏈表,鏈表中的元素將來自該數組,但也可以重復,按順序對鏈表進行排序,元素將出現在數組中。 可以假定該數組覆蓋了鏈表的所有元素。 arr [] = ![](https://img.kancloud.cn/bc/ca/bcca9d783b464274a706ea8bdd437d0e_202x42.png) 列表= ![](https://img.kancloud.cn/48/27/4827e72d0b6b7d0686c25c7d2c1e369a_681x41.png) 排序清單= ![](https://img.kancloud.cn/60/d1/60d1056acdc58ecb05ad6d7acfa3a53b_681x41.png) 在[中被問及亞馬遜](https://www.geeksforgeeks.org/amazon-interview-experience-set-424-sde-2/) 首先,創建一個散列表,以存儲鏈表中元素的頻率。 然后,只需遍歷列表,并為 arr [i]的每個元素檢查 has 表中的頻率,并通過 arr [i]元素修改列表數據,直到其頻率,最后打印列表。 ## C++ ```cpp // Efficient CPP program to sort given list in order // elements are appearing in an array #include <bits/stdc++.h> using namespace std; // Linked list node struct Node { ????int data; ????struct Node* next; }; // function prototype for printing the list void printList(struct Node*); // Function to insert a node at the // beginning of the linked list void push(struct Node** head_ref, int new_data) { ????struct Node* new_node = new Node; ????new_node -> data = new_data; ????new_node -> next = *head_ref; ????*head_ref = new_node; } // function to print the linked list void printList(struct Node* head) { ????while (head != NULL) { ????????cout << head -> data << " -> "; ????????head = head -> next; ????} } // Function that sort list in order of apperaing // elements in an array void sortlist(int arr[], int N, struct Node* head) { ????// Store frequencies of elements in a ????// hash table. ????unordered_map<int, int> hash; ????struct Node* temp = head; ????while (temp) {???????? ????????hash[temp -> data]++; ????????temp = temp -> next; ????} ????temp = head; ????// One by one put elements in lis according ????// to their appearance in array ????for (int i = 0; i < N; i++) {???????? ????????// Update 'frequency' nodes with value? ????????// equal to arr[i] ????????int frequency = hash[arr[i]]; ????????while (frequency--) { ????????????// Modify list data as element? ????????????// appear in an array ????????????temp -> data = arr[i]; ????????????temp = temp -> next; ????????} ????} } // Driver Code int main() { ????struct Node* head = NULL; ????int arr[] = { 5, 1, 3, 2, 8 }; ????int N = sizeof(arr) / sizeof(arr[0]); ????// creating the linked list ????push(&head, 3); ????push(&head, 2); ????push(&head, 5); ????push(&head, 8); ????push(&head, 5); ????push(&head, 2); ????push(&head, 1); ????// Function call to sort the list in order ????// elements are apperaing in an array ????sortlist(arr, N, head); ????// print the modified linked list ????cout << "Sorted List:" << endl; ????printList(head); ????return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看