THE LONGEST THREAD.

  • Wanna Join? New users you can now register lightning fast using your Facebook or Twitter accounts.
Jul 21, 2002
8,158
665
0
42
Oklahoma
www.youtube.com
Nightbreed said:
sdfkjhakjhfkjashdflkjsadflkjhaslkdfhaskdhflksadhflkasdhflaskdhflaskdhflksadhflkasdhfklashdflkashdflkashdflsahflkashflkashfdlkjashfdlkbsm,fnxc,mnvlxkcjviouewriqjEWRQIOPWEFJLMXDNVJKEGFOUQWLMEFUIWQHTLKWENF8324U5WKENMRFIQ2U4YRL3WNMRF98Q234YRTLKESNFSAYUDFHQND;QK;WEKPQWOJETOIQREWT0834JTLEJRHGOPJDGL;KWENTUERG0IWERJT893247T64PEWOJTOI2Q4Y5R0823UHJ4OJG237R2T39H54KJ34HTRI3Y4095JTL34HNTOU34UP5J32498T53487M5C9F4INM08934UBNV307459032745-324NM5-9218WMXLAKD;LSAJFLSAKJDVDSLMNGN,LSDABFLSAHO345325-0GFUDSOIJSLJGLDSJLJL;JLJlkj;lijdsliglsdhfgksjdhfgoudfsuhfgujdfnhg9ifdugiojdf9dugwelkrjjtyoiwetrouweyjkfrhghasjklhglsah;alhd;lkjas;hglj,bv,cxbvx,cnbvksdghfljkasdgdskjyoewruqytpoweqiy50328978904326tukerhtiutpouerhfjkdhf,xdmvnx,m.cbvljwakhgkjshdflakjfhopwqieytpouiywqpoyqtouwre50843275603824175-98347rljesytpouwhwtepyteopuirhaskljdfhgasl;dfjgh;dsljahga,mnv.,nv.,mznxc,xb,.xcmnvl;ksafdghs;lkahdg;lasdhgoierqytpoewriytewruiop57w098324679328476-5932847truoeytpeuiruioehglkjdsahgksajhfdag,xcnv,xmcnvc,xcmnvxcm,xmhgjkl;sdhgkldwfhgfjkdtyiorewytioewyt0-324760-324793ytewruopotweuytfdskjhg;dsfkajhgljdasfhgk;jsdah;fjvxz,chv,mxcnv.,xmcbv.,xzbv.,msa;ljkhgsd;lahg;lsadl;jdshf;ljhfsda;ljhfsdjklhwpoeuytpoewruiytpouewrytpouewroptuyeprowuit983498634726890327469083467230986790328790348267ieuwriewrutiouerwytepouie4tuopeywrpoturpewoqruytpouweqiytkpjhdsf;kljasdflkjghlkasglkjadgkjd,mvcnb,.mcxvnb,zmxbc.,xzcnvb.,mvc.,mn/.n,XCB/.m,NB<>?mcNB?X<CMNbkldajg;lskdfj'dlkajgs'dlkhgl'skdGHKjgeowruitruiopeyqoytouipewry5 9-823476-9832476-983276-34786riytouerytpuioeqwrytopuyoqyt[oeqwrhgdfjshgj;dlfhfg'ladhgalds'hfg'lahkhg'lnxcv,mxvb,/czxmbv/m,xzbm,.xczbn/,xcmnb,/mxnl;jfdg'ladsfkhgljdagk;hdaf;ljgkhfl;dasjkthoeriyto[ierywtopiewrytiperwoutioerut[oeir7yt089347508327=034u6320847-iowtypqwuiotpowjqyetuopqerwtkleqsjthgl;sajdhg;skdjhgldasjglsdahl;gjsdakbnm,dsg;hg,mcxnv/xmnvm,.zCXBm,.cxbv,m/xBNvm,.czxnv/m,.xch;klsdhtg;jlrskdhg;ljdshg;ldsjhgkj;4ryuotuipewqytiuptwqyt-934786 39180609324876903478y69078312454893276934789uoiytwreiuotoiwquytwoeiutwyqihtiwqeuytwojqehyiqwuehytoiwuqyeiuwqyiojdhsdakjhasglm;h;kasjhkSHGK;JDSK;JHA'LSHAD'LHGADFLHDFSHLHDSFM,CVX.,MC,M.BCV,CNV,.NCB,CVMXNXC,.MVNB,CXVM.B,MCVXB,M.C,J.XCMNXZC,HJNLDFSJNDSFKLJHDLIHDLSH'ADLSKHA'LKH
uoiperwuypeiwrueiwuye[wiuyeprwiuerywpiueywruerywi5ueio7589=-689-3467=03=90630=346927347084327=0708=oeiroiyurewio[rpuoewetipywtyiqoyio-qwtypwtyopwtytytytwypotewyo[tegashldkahglsghlaghsgldglshlghlksgashghdasklghlhlkhklhlkagsdgasdagsdgasdgasdgsdm,n,.nmnmczvvczxvvcvZzxvchhjhklhlhjsfdafdasfdasafduioyuuiop8opuyopyopyioteqwtwqtwqtweqtewteqwtweqtweq07897897890789078905455334hlhjhjhsdam,hfgklasjhgkjaxndfjkvhsajkvnhjjkggjklhghjgddvcwygdhjngnhcmnfgjlahsdfjhnasdjfaklsbfSFNDBH

amen. [/B]


preach on brother
 
Jul 7, 2002
3,105
0
0
Code:
/* 
 * Assignment3-Operations on Lists.
 * Functional approaches. Recursive.
 */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

typedef int boolean;
typedef char data;
typedef struct node 
		{
			data info;
			struct node *next;
		}list_node;

typedef list_node list_head;
typedef list_head *list;

list L;

list nullist()                          /* return an empty list */							
{
	L=(list_head *)malloc(sizeof *L);
	L->next=NULL;

	return(L);
}

boolean null(list L)					/* Test an empty list */
{
  return (L->next== NULL);
}

data car(list L)		/* obtain the first element of given list */
{
  return (L->next->info);
}

list cdr(list L)				/* obtain the rest of the list */
{
  list_head *cdr_head;
  cdr_head=nullist();
  cdr_head->next = L->next->next;

  return (cdr_head);
}

list cons(data alpha, list L)	/* insert an element into a list */
{
  list_node *insert=nullist();
  list_head *cons_head=nullist();

  insert->info = alpha;
  insert->next = L->next;

  cons_head->next = insert;
  return (cons_head);
}

data read_element()                    /* to skip spaces */
{
  data letter;
  letter = getchar();

  while(isspace(letter)) letter=getchar();

  return(letter);
}

list readlist_element(void)              /* to read in elements */
{
  data letter;
  letter = read_element();

  if (letter == ')')
    return(nullist());
  else 
    return(cons(letter, readlist_element()));  
}

list readlist(void)						/* to start reading a list */
{
  data letter;
  letter = read_element();

  if (letter == '(')
    return(readlist_element());
  else if(isalpha(letter)||(48<=letter&&57>=letter))
    printf("Error on input format. \n");
	return(0);
}

void print(list L){						/* to print out a list */
	 
  if(null(L))
	  printf(")\n");
  else 
  { 
    printf("%c", car(L));
	printf(" ");
	print(cdr(L));
  }
}

void printlist(list L)
{
   	printf("(");
	printf(" ");
    
	print(L);
 }

int length(list L){		/* Returns the number of elements in the list */
	if(null(L)) return 0;
	else
	return 1+length(cdr(L));
}

list append(list L1, list L2){   /* Returns the concatenation of two lists */
	if(null(L1))
		return L2;
	else return
		cons(car(L1), append(cdr(L1), L2));
}

list reverse(list L)			/* Returns the reverse of a list */
{if(null(L)) return nullist();
 else return
	 append(reverse(cdr(L)), cons(car(L), nullist()));
}

main()
{
  list one;
  list two;
  list ap, rv1, rv2;
									/* Get lists */
  printf("Enter first list>>");
  one=readlist(); 
  printf("Enter second list>>");
  two=readlist();
  
									/* Display list one */
  printf("First list : ");
  printlist(one);
  printf("Length = %d\n", length(one));
  rv1=reverse(one);
  printlist(rv1);
  printf("\n");
									/* Display list two */
  printf("Second list : ");
  printlist(two);
  printf("Length = %d\n", length(two));
  rv2=reverse(two);
  printlist(rv2);
									/* Append two lists */
  ap=append(one, two);
  printf("Append : ");
  printlist(ap);

}