c_cpp 练习链表cpp

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 练习链表cpp相关的知识,希望对你有一定的参考价值。

#include <iostream>

//basic int node for linked list
struct intNode {
	int item;
	intNode * next;
};
//uses compound initalizer to make a node.
intNode getnode(int arg) {
	return intNode{arg};
}


//makes a linked list of some length
intNode makelist(int length){
	intNode base = {0};
	for(int i=1;i<length;i++){
		base = intNode{i, &base};
	}
	return base;
}

//traverse a linked list and print the contents
void traverse(intNode list){
	intNode * point = &list;
	do {
		intNode hold = *point;
		std::cout << hold.item << std::endl;
		point = hold.next;
	} while(list.item != 0);
}

int main() {
	intNode f = makelist(8);
	traverse(f);
}
/*7
-1437250888
exited with non-zero status*/

以上是关于c_cpp 练习链表cpp的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 反转链表的.cpp

c_cpp 合并两个排序的链表的.cpp

c_cpp 复杂链表的复制的.cpp

c_cpp 反转链表

c_cpp Ç链表操作

c_cpp c链表