Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
WrongWay reversible iterator Copyright(C) 2016 Henry Kroll III www.thenerdshow.com
//WrongWay reversible iterator Copyright(C) 2016 Henry Kroll III www.thenerdshow.com #include <stdio.h> typedef float some; typedef struct { size_t pos, start, end; some *ptr; some *(*next)(piter); } iter, *piter; //iterator next some *next (piter i) { return i->pos <= i->end? &i->ptr[i->pos++] : NULL; } //iterator previous some *prev (piter i) { return i->pos >= i->start? &i->ptr[i->pos--] : NULL; } //shortcuts #define ITER(name, start, end) &(iter){start, start, end, name, &next} #define FOREACH(i, j) for (some *j;(j = i->next(i));) #define NEXT(i) *i->next(i) #define REVERSE(i) { if(i->pos>i->start){i->next = prev, i->pos=i->end;}\ else{ i->next = next, i->pos = i->start;}}while(0) int main (void) { some i[]={0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; //wrap i in an iterator kind of like python's iter() piter k = ITER(i, 2, 6); printf ("%1.2f\n", NEXT(k)); printf ("%1.2f\n", NEXT(k)); FOREACH (k, j) printf ("%1.2f ", *j); REVERSE(k); putchar ('\n'); FOREACH (k, j) printf ("%1.2f ", *j); REVERSE(k); putchar ('\n'); FOREACH (k, j) printf ("%1.2f ", *j); REVERSE(k); putchar ('\n'); printf ("%1.2f\n", NEXT(k)); printf ("%1.2f\n", NEXT(k)); printf ("%1.2f\n", NEXT(k)); printf ("%1.2f\n", NEXT(k)); return 0; }
run
|
edit
|
history
|
help
0
eliminate_duplicates.c
Spring 2017 Lab 4 v1
2-dimension array got area by malloc()
Primo compuesto
pointer example 2
print_odd_pointer.c
Pointer
150108_RecursividadFibonacci
24-June-2015
150116_MatrizOrdenada