Category : C Source Code
Archive   : LLST1201.ZIP
Filename : LISTDEMO.C

 
Output of file : LISTDEMO.C contained in archive : LLST1201.ZIP
#include

#define NELEMS 10

struct LST_DATA
{ int elem1;
int elem2;
};

typedef struct LST_DATA DATA_T;

main()

{ int floop, delnum;

void do_it(struct LST_DATA *);

DATA_T data_ary[NELEMS];
DATA_T *data_ptr[NELEMS];
DATA_T *dtemp;
HEAD_T *list1, *list2;
LINK_T *temp1, *temp2;

printf("\nInitializing data array.");
for (floop = 0; floop < NELEMS; ++floop)
{ data_ptr[floop] = &data_ary[floop];
data_ary[floop].elem1 = floop;
data_ary[floop].elem2 = floop * 10;
}

printf("\nInstantiating list1.");
list1 = inst_list(); /* create list1 */

printf("\nFilling list 1.\n");
for (floop = 0; floop < 5; ++floop)
add_last(data_ptr[floop], list1); /* and fill it */

printf("\nNow to traverse the list!\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n");

printf("\nInstantiating list2.");
list2 = inst_list(); /* create list1 */

printf("\nFilling list 2.\n");
for (floop = 5; floop < NELEMS; ++floop)
add_last(data_ptr[floop], list2); /* and fill it */

printf("\nNow to traverse the second list!\n\t");
temp2 = list2->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp2->L_DATA->elem1, temp2->L_DATA->elem2);
temp2 = temp2->L_NEXT;
}
printf("\n");

printf("\nThis will delete the first link.");
del_first(list1);
printf("\nNow to show the new list!\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n");

printf("\nThis will put the first link back at the end!");
add_last(data_ptr[0], list1);
printf("\nAnd here we have the list:\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n");

printf("\nThis will delete the third link.");
dtemp = del_link(list1, 3);
printf("\nNow to show the new list!\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n");

printf("\nThis will put the third link back after the new third!");
add_after(dtemp, list1, 3);
printf("\nAnd here we have the list:\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n");

printf("\nNow, we'll move elements 2-4 from list 2 to list 1, after element 2!");
move_list(list2, list1, 2, 4, 2);
printf("\nAnd here we have the new lists:");
printf("\n\tLIST 1:\n\t");
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}
printf("\n\tLIST 2:\n\t");
temp2 = list2->L_FIRST;
for (floop = 0; floop < list2->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp2->L_DATA->elem1, temp2->L_DATA->elem2);
temp2 = temp2->L_NEXT;
}
printf("\n");

printf("\nNow, we will delete links 3-5 in list 1!\n\t");
delnum = del_from_to(list1, 3, 5, do_it);
printf("\nAnd here we have the new list 1:");
printf("\tDeleted %d links\n\t", delnum);
temp1 = list1->L_FIRST;
for (floop = 0; floop < list1->L_LENGTH; ++floop)
{ printf("(%d, %d) ",
temp1->L_DATA->elem1, temp1->L_DATA->elem2);
temp1 = temp1->L_NEXT;
}

printf("\nNow to destroy the list(s)!\n");
purge_list(list1);
purge_list(list2);

printf("\nNow, to exit. Cheerio!\n");
}


void do_it(data)
struct LST_DATA *data;

{ return;
}


  3 Responses to “Category : C Source Code
Archive   : LLST1201.ZIP
Filename : LISTDEMO.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/