assignment5

Null pnextnull pdatadata return p function

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: de ∗ ) m a l l o c ( s i z e o f ( s truct n ode ) ) ; i f ( p !=NULL) { p−>next=NULL; p−>data=data ; } return p ; } /∗ @function @ desc @param @param @ return addfront a dds n ode t o t h e f r o n t o f t h e l i s t h ead [ IN ] c u r r e n t h ead o f t h e l i s t d ata [ IN ] d ata t o b e i n s e r t e d u pdated h ead o f t h e l i s t ∗/ s truct n ode ∗ a d d f r o n t ( s truct n ode ∗ h ead , i n t d ata ) { struct n ode ∗ p=n a l l o c ( data ) ; i f ( p==NULL) r eturn h ead ; / ∗ n o c hange ∗ / p−>next=head ; r eturn p ; } /∗ @function @ desc @param display d i s p l a y s t h e n odes i n t h e l i s t h ead [ IN ] p o i n t e r t o t h e h ead n ode o f t h e l i s t ∗/ v oid d i s p l a y ( s truct n ode ∗ h ead ) { struct n ode ∗ p=NULL; p r i n t f ( " list :" ) ; f o r ( p=head ; p!=NULL; p=p−>next ) p r i n t f ( " %d " , p−>data ) ; p r i n t f ( " \n" ) ; } / ∗ @ f u n c t i o n a ddback 2 @ desc @param @param @return a dds n ode t o t h e b ack o f t h e l i s t h ead [ IN ] c u r r e n t h ead o f t h e l i s t d ata [ IN ] d ata t o b e i n s e r t e d u pdated h ead n ode ∗/ s truct n ode ∗ a ddback ( s truct n ode ∗ h ead , i n t d ata ) { struct n ode ∗ p=n a l l o c ( data ) ; s truct n ode ∗ c u r r=NULL; i f ( p==NULL) r eturn h ead ; / ∗ s p e c i a l c a s e : e mpty l i s t ∗ / i f ( h ead==NULL) { head=p ; return p ; } else { / ∗ f i n d l a s t e l e m e n t ∗ / f o r ( c u r r=head ; c u r r −>next !=NULL; c u r r=c u r r −>next ) ; c u r r −>next=p ; return h ead ; } } /∗ @function f r e e l i s t @ desc f r e e s the element o f the l i s t @param h ead [ IN ] p o i n t e r t o t h e h ead n ode ∗/ v oid f r e e l i s t ( s truct n ode ∗ h ead ) { struct n ode ∗ p=NULL; w hile ( head ) { p=head ; head=head−>next ; f r e e ( p ) ; } } /∗ @function @ desc @param @param @ return find finds h ead d ata NULL t h e e l e m e n t s t h a t c o n t a i n s t h e g i v e n d ata [ IN ] p o i n t e r t o t h e h ead n ode [ IN ] p a y l o a d t o m atch i...
View Full Document

This document was uploaded on 03/17/2014 for the course EECS 6.087 at MIT.

Ask a homework question - tutors are online