摘要: 问题描述一堆数(例如6, 2, 2, 6, 3, 4, 6, 6, 6, 6),总共10个,其中”6“的个数超过总数的一半5,找出这个个数超过过半的那个数。思路从头到尾遍历,两个数相同接着往后遍历;否则删掉这两个数,接着往后遍历。因为所找的那个数过半,所以不同的数相抵,抵消掉最后还会至少剩下一个那个要找的数。图示代码#include using namespace std;typedef struct node{ int num; node *before; node *next;}node;int main(){ node *p_now, *p_next; no... 阅读全文
posted @ 2013-07-17 22:39 jihite 阅读(1400) 评论(0) 推荐(0) 编辑