當談到C++時,我是世界上最基本的人,我想知道如果你們能幫我解決問題,那麼你們是否可以幫助我。我試圖對讀取到istream的節點進行排序,但是它們是在讀入的。網絡上的代碼非常複雜,我想知道是否有一個非常基本的方法來實現這一點。當插入到istream中時,對單個鏈表進行排序C++
這是我讀法,至今它讀入這是偉大的istream的,但現在我需要將其排序爲在讀。我的頭好痛哈哈
void ListClass::Read(istream& r)
{
char c[13];
r >> c;
r >> numberOfInts;
Node *node = new Node();
head = node;
for(int i = 0; i < numberOfInts; i++)
{
r >> node->data;
cout << node->data << endl;
node->next = new Node;
node = node->next;
}
}
,這裏是我的節點類我的頭文件
class Node
{
public:
Node() {} //default constructor
Node(int d, Node* q = 0) : data(d), next(q) {} //constructor with parameters data and next
int data; //holds data in node
Node* next;//pointer to next node
};
您遇到的方法(「網上的代碼」)是什麼? (只是爲了避免人們向你推薦同樣的東西) – jonsca 2011-04-27 13:22:04
其中一個是模板方法,另一個更適合雙鏈表和其他幾個人,但即使是解釋它的人也會感到困惑。基本上我正在尋找某種插入排序我想,但是在尋找它的時候,除非過於複雜,否則沒有太多的東西 –
2011-04-27 13:24:09
@jonsca對不起忘了標記 – 2011-04-27 13:25:00