# 被换行符折磨的日子

-------------------------

John2Bill1Kim3Christos3Alex4Jo8Jo6Alex9

r1w1

r：即读取，后面接1，意思是读取文件名为[data_1.txt]

w：即写出，后面接1，存为文件名[output_1.txt]

r1sdAlexdJohniKim-10iFu100iZu50dKaterinadBillw15

d：删除名称为Alex的item

i：插入名称为Kim,编号为-10

bool getline(std::ifstream &is,std::string &str){	bool b = std::getline(is,str);	std::string::size_type p = str.find_last_of('\r');	if(p != std::string::npos) str.erase(p);	return b;}

int list_sort(_list *list){	int count = 0, i = 0, j = 0;	list_item **iter_array;	list_item *iter;	if (list == NULL)		return -1;	//计算元素个数便于分配内存	count = list_count(list);	iter_array = (list_item**)malloc(sizeof(list_item*)*count);		//将链表数据拷贝到数组,便于冒泡排序	iter = list->next;	while(iter != NULL){		iter_array[i++] = iter;		iter = iter->next;	}	for (i = count - 1; i>=0; i--) {		for (j = 0; j < i; j++){			if ((*iter_array[j]).ID > (*iter_array[j+1]).ID){				iter = iter_array[j];				iter_array[j] = iter_array[j+1];				iter_array[j+1] = iter;			}					}	}	//重建链表	list->next = iter_array[0];	for (i = 0; i< count; i++)	{		if(i == count -1){			iter_array[i]->next = NULL;			break;		}		iter_array[i]->next = iter_array[i+1];	}	return 0;}

Technorati 标签: ,,,,
posted @ 2010-02-10 17:55  冷侃  阅读(...)  评论(...编辑  收藏