当前位置:首页 > iai > 正文

C++链表模拟

#include <iostream>
using namespace std; 
struct Stu{
	int score;
	Stu *prev;
	Stu *next;
};
Stu *head = (Stu*)malloc(sizeof(Stu)), *t, *INDEX;
int main(){ 
	int n, score, s = 0;
	cin >> n;
	INDEX = head;
	while(n--){
		cin >> score;
		t = (Stu*)malloc(sizeof(Stu));
		t->next = nullptr;
		t->score = score;
		INDEX->next = t;
		INDEX = t;
	}
	INDEX = head->next;
	while(INDEX != nullptr){
		s += INDEX->score;
		INDEX = INDEX->next;
	}
	cout << s;
	return 0;
}


上一篇
二叉树的建立

下一篇
临时用

有话要说...