首页 > > 详细

C++辅导单链表排序 Data Structures讲解C/C++、C/C++语言解析

 

Requirement

Using C++ Class and pointers, implement Single-Linked List of integers. You are not allowed to use STL. Consider the following for your linked list implementation:

  • Update the List class implementations in the lecture slides so that the List does not have any duplicate value.
  • Also make the necessary updates to the List class to maintain a sorted list (i.e. the Nodes are in increasing order of data values). In particular, replace all the insert methods, and replace them with insert(int x), which inserts x in the right position so that the List remains sorted.
  • Implement DeleteMid() to delete the middle element (when the list contains an odd number of elements) or middle two elements (when the list contains an even number of elements).
  • Using recursion, implement Ascend() and Descend() to display the entire list in ascending and descending orders, respectively.

Sample Input

3               // Total no of input sets
5 10 4 4        // Input set 1
1 5 3 5 9 -1 7  // Input set 2
5 4 3 2 -999    // Input set 3

Sample Output (for Input set 1)

Sorted List: 4 5 10

After Deleting Middle Element:
List: 4 10

Display List in Ascending Order:
4 10

Display List in Descending Order:
10 4

and so on for other sample input sets 2 and 3
联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!