[ create a new paste ] login | about

Link: http://codepad.org/ZkghZJHk    [ raw code | output | fork ]

C, pasted on Jul 25:
#include <stdio.h>
struct addressSheet {
  int a, b;
};

void swap1(struct addressSheet ary[], int i, int j) {
  struct addressSheet tmp;
  tmp = ary[i];
  ary[i] = ary[j];
  ary[j] = tmp;
}

void swap2(struct addressSheet ary[], int i, int j) {
  struct addressSheet *tmp;
  tmp = &ary[i];
  ary[i] = ary[j];
  ary[j] = *tmp;
}

int main() {
  static struct addressSheet addressSheetTable[] = {
    {1, 11}, {2, 22}, {3, 33}, {4, 44}, {5, 55} };
  int i;
  int n = sizeof(addressSheetTable) / sizeof(addressSheetTable[0]);

  for (i = 0; i < n / 2; i++) 
    swap1(addressSheetTable, i, n - 1 - i);
  for (i = 0; i < n; i++)
    printf("%d:%d\n", addressSheetTable[i].a, addressSheetTable[i].b);
  putchar('\n');
  
  for (i = 0; i < n / 2; i++) 
    swap2(addressSheetTable, i, n - 1 - i);
  for (i = 0; i < n; i++)
    printf("%d:%d\n", addressSheetTable[i].a, addressSheetTable[i].b);

  return 0;
}
/* end */


Output:
1
2
3
4
5
6
7
8
9
10
11
5:55
4:44
3:33
2:22
1:11

1:11
2:22
3:33
2:22
1:11


Create a new paste based on this one


Comments: