Line 369: Line 369:
  
 
===============================
 
===============================
Kevin Tan(0023987592), section#2  notes 03/29
+
Kevin Tan(0023987592), section#2  notes 03/27
  
  

Revision as of 11:15, 8 April 2012

Lecture 19 - 3/27 - John Ribeiro - Lu

typedef struct listnode {

 struct listnode *next; // don't forget *
 int value;

} Node;

Node * Node_construct ( int n ) {

 Node * n;
 n = malloc ( sizeof ( Node ) );
 n -> next = NULL; // Very common mistake to forget this
 n -> value = v;
 return n;

}

Node * List_insert ( Node * head, int v ) {

 Node * n = Node_construct ( v );
 n -> next = head; // Key to how the linked list works
 return n;

}

// The insertion is like a stack, first in, last out

void List_print ( Node * head ) {

 Node * p = head;
 while ( p != NULL )
 {
   printf ( " %d \n ", p -> value );
   p = p->next;
 }

}

void List_destroy ( Node * head ) {

 Node * p;
 Node * q;
 p = head;
 while ( p != NULL )
 {
   q = p ->next;
   free ( p );
   p = q;
 }

}

How to use this?

Node * head = NULL; // Must Initialize head = List_insert ( head, 6 ); head = List_insert ( head, 29); head = List_insert ( head, -74 ); List_print ( head ); List_destroy ( head ); head = NULL; // Must redefine head to point to NULL

Node * head = NULL;

while ( still data ) {

 head = List_insert ( head , data );

}

OR

do {

 scanf ( "%d", &value );
 if ( value != 0 )
 {
   head = List_insert ( head, value );
 }

} while ( value != 0 );

=> All of the data in the list.

Node * List_search ( Node *p, int v ) {

 while ( p != NULL )
 {
   if ( p -> value == v )
   {
      return p;
   }
   p = p -> next;
 }
 return p; /* OR NULL */

}



Lecture 20 3/27 _ Kailu Song

(Application of link list) typeof struct listnode { struct list node *next; int value; }Node;

Node *Node_construct (int u) { Node *n; n = malloc(sizeof(Node)); n -> next = NULL; n->value = u; return n; } Node *List_insert(Node *h, int v) { Node *n = Node_construct(v); n -> next = h; return n; }

void List_print(Node *h) { Node *p = h; while (p != NULL) { printf("%d\n", p->value); p=p->next; } }

void List_destroy (Node *h) { Node *p; Node *q;

	p = h;

while (p!= NULL) { q = p->next; free℗; p = q; } }

void main() { Node *head = NULL; head = List_insert(head,6); head = List_insert(head,29); head = List_insert(head,-74); List_printf(head); List_destroy(head); head = NULL; }





ECE264 LEC19 Shiyu Wang April 1

typedef struct listnode {

 struct listnode *next;
 int value;

}Node;

Node *Node_construct(int v) {

 Node *n;
 n=malloc(sizeof(Node));
 n->next=NULL;
 n->value = v;
 return n;

}

Node *List_insert(Node*h,int u) {

 Node *n = Node_construct(u);
 n->next=h;
 return n;

}

Void List_Print(Node*head) {

 Node*p = head;
 while(p!=NULL)
 {
   printf("%d\n",p->value);
   p=p->next;
 }

}

Void List_destroy(Node *head) {

 Node *p;
 Node *q;
 p=head;
 while(p!=NULL)
 {
   q=p->next;
   free(p);
   p=q;
 }

}


How to use

Node * head=BULL;

head = List_insect(head,6);

head = List_insect(head,29);

head = List_insect(head,-74);

List_print(head);

List_destroy(head);


Node*head = NULL; do {

 scanf("%d",&value);
 if(value!=0)
 {
   head = List_insect(head,value);
 }while(value!=p);


Node *List_search(Node *p, int v) {

 while(p!=NULL)
 {
   if((p->value)==v)
   {
     return p;
   }
   p=p->next;
 }
 return p;

} /***********************************************************************

ECE264 LEC19 Hanye Xu April 1

typedef struct listnode {

   struct listnode *next;
   int value;

}Node;

Node *Node_construct(int v) {

 Node *n;
 n=malloc(sizeof(Node));
 n->next=NULL;
 n->value = v;
 return n;

}

Node *List_insert(Node*h,int u) {

 Node *n = Node_construct(u);
 n->next=h;
 return n;

}

Void List_Print(Node*head) {

 Node*p = head;
 while(p!=NULL)
 {
   printf("%d\n",p->value);
   p=p->next;
 }

}

Void List_destroy(Node *head) {

 Node *p;
 Node *q;
 p=head;
 while(p!=NULL)
 {
   q=p->next;
   free(p);
   p=q;
 }

}


main

Node * head=BULL;

head = List_insect(head,6);

head = List_insect(head,29);

head = List_insect(head,-74);

List_print(head);

List_destroy(head);


Node*head = NULL; do {

 scanf("%d",&value);
 if(value!=0)
 {
   head = List_insect(head,value);
 }while(value!=p);


Node *List_search(Node *p, int v) {

 while(p!=NULL)
 {
   if((p->value)==v)
   {
     return p;
   }
   p=p->next;
 }
 return p;

}


/***********************************************************************

ECE264 HUAYI GUO professor Niklas Elmqvist //Lecture0321 /* ipa2 Generate "super" Blokus Pieces

to take any number of blocks to generate any comfigarition of pieces Not allowed to illimulate rotations ,mirrors and tranlated versions.

stage one: Integer partitions Taking a number and split it into partitions.



  • /

void intpart(int badget, int pos, int *data) {

  int i;

  //Base case;
  if(badget == 0){
     //print postions

return;

  }
  //recursive case:
  for(i = 1; i <= badget; i++){
     data[pos]==i;
     intpart(badget - i, pos+1,data);
  }
  return;

}

===================

Kevin Tan(0023987592), section#2 notes 03/27


4 = [4] =[3 1] [1 3] =[2 1 1][1 1 2][1 2 1] =[1 1 1 1]

void intpart(int*array, int budget, int pos) {

 if(budget == 0)
 {
   printpartition(array, pos-1);
   
 }
 int spending = 0;
 for (speding=1;spend<=budget;spending+1)
 {
   array[pos] = spending;
   intpart(array,budget-spending,pos+1);
 }

}

int main(int argc, char*argv[]) {

 int n = strtol(argv[1],NULL,10);
 int *array = malloc(n*sizeof(array));

}

Alumni Liaison

ECE462 Survivor

Seraj Dosenbach