All pastes #222967 Raw Edit

Miscellany

public text v1 · immutable
#222967 ·published 2006-10-26 17:37 UTC
rendered paste body
list* ttol(int *tbl, int x, int y)
{
	int cnt1,cnt2;
	node *tmpnode;
	list *mylist = (list*)malloc(sizeof(list));

	mylist->head = NULL;
	mylist->tail = NULL;
	
	tmpnode = list_createitem(x,y,0); /*1st node with dimentions */
	list_additem(mylist, tmpnode);
	/*search table for Non-zero "cells" */
	for (cnt1 = 0; cnt1 < y; cnt1++){
		for (cnt2 = 0; cnt2 < x; cnt2++){
			if (tbl[cnt1*x + cnt2] != 0){ /*not zero */
				tmpnode = list_createitem(cnt1,cnt2,tbl[cnt1*x + cnt2]);
				list_additem(mylist, tmpnode);
			}
		}
	}
	return mylist;
}








===============================
78      0       28
39      0       62
0       0       0
0       64      0

X       Y       VAL
3       4       0
0       0       78
0       1       39
2       1       64
2       2       28