In Linked Lists Following Steps Are Required
In Linked Lists Following Steps Are Required
Linked Lists are another useful data structure. It has great advantage over Array data structure. In comparison to array it is more advantageous in the following senseIn Array as a programmer we have to specify the size/capacity of that array. This restriction is dangerous whenever we need to maintain extra record eyond specified size. Also in case of less record then size. In this case a lot of memory cells are wasted. If array is full! it is never possi le to further store extra records in this array.
IN LINKED REQUIRED:
LISTS
FOLLOWING
STEPS
ARE
IMPORTANT TERMS:
(ode1 The components which form the list. Temp1 "ontains the temporary address which is pointer varia le. ,ead1 "ontains the address of first node. "/node1 "ontains the address of current node. (ext1 "ontains the address of next node. If there is only one node in the list then it holds )(*LL+.
"reation of memory #using malloc $%&. "ollection the ase address returned y malloc $% into a temporary pointer varia le. 'toring own data into the information part of the node. (ow store data into the node. 'tore )(*LL+ into the next part of the node. If head contains )(ull+ then ,ead-temp prev info next .lse c/node-0 next-temp And at last store temp into c/node.
[email protected] data into list1AnB%= scanf$@CdB!Ddata%= if$head--(*LL% < temp-$struct node>%malloc$sizeof$struct node%%= temp-0info-data= temp-0next-(*LL= head-temp= c/node-temp= ?
else < temp-$struct node >%malloc$sizeof$struct node%%= temp-0info-data= temp-0next-(*LL= c/node-0next-temp= c/node-temp= ? [email protected] E to "ontinueFFFAnB%= ?while$ch--+y+GGch--+E+%= printf$@Linked List successfully "reatedAnB%=
int n= c/node-head= [email protected] a .lement To searchAn B%= scanf$@CdAn!DnB%= printf$@The List .lements are at Cdth no. AnB!n%= while$c/nodeH-(*LL% < printf$@CdAnB!c/node-0info%= if$c/node-0info--n% Ireak= c/node-c/node-0next= ?
data
at
t*e
&'(ode "or Insertion o" a data at t*e End O" Link List'&
temp-$struct node >%malloc$sizeof$struct node%%= struct node >cnode-head= while$cnode-0nextH-(*LL% < "node-cnode-0next= ? temp-0info-data= temp-0next-(*LL= cnode-0next-temp= ?
data
"ro-
spe,i"ied
struct node >ptr!>temp= int i!pos= [email protected] Josition to 3eleteAnB%= scanf$@CdB!Dpos%= ptr-head= for$i-5=i:-pos=iLL% < temp-ptr= ptf-ptr-0next= ? printf$@The (*4I.2 Nhich * have deleted is CdB!ptf-0info%= temp-0next-ptf-0next= free$ptr%= ?
<
0$ (IR(ULAR LINKED
temp-0num-data= temp-0next-head= head-temp= rear-temp= ? else < temp-$struct node >%malloc$sizeof$struct node%%= temp-0num-data= temp-0next-head= rear-0next-temp= rear-temp= ? ?
num-$struct node >%malloc$sizeof$struct node%%= [email protected] a .lement1B%= scanf$@CdB!Dnum-0info%= num-0next-head= prv-0next-num= head-temp= ?
0nd Met*od
In dou ly linked list! each structure type node contains 7 parts1 Info! (ext D Jrv. )Jrv+ contains the address of Qust previous node. )(ext+ contains the address of Qust next node and )Info+ contains the information $varia le%.
void create$% < do< temp-$struct node >%malloc$sizeof$struct node%%= [email protected] *r 3ataB%= scanf$@CdB!Dtemp-0info%= if$front--(*LL% < temp-0next-(*LL= temp-0prv-(*LL= rear-front-temp= cnode-temp= ? else < temp-0next-(*LL= temp-0prv-cnode= cnode-0next-temp= cnode-cnode-0next= rear-temp= ? [email protected] E to "ontinue1B%= ch-getche$%= ?while$ch--+y+GGch--+E+%= ?
&'Insertion At Front'&
void insert/ eg$int data% < node >ptr= prt-$node >%malloc$sizeof$node%%= ptr-0info-data= ptr-0prv-(*LL= ptr-0next-front= front-0prv-ptr= front-ptr= ?
&'De etion o" a Node "ro- spe,i"ied position in Do12 ! Linked List'&
4i5 First Met*od void del/spe$% < struct node >case5!>yahoo!>ali!>ptr= int data!c-K= [email protected] Josition of nodeB%= scanf$@CdB!Ddata%= case5-front= if$data--K% < ptr-front= free$ptr%= front-front-0next= front-0prv-(*LL= ? else < while$case5H-(*LL% < cLL= if$c--$data-5%% < ptr-case5= ? if$c--data% < yahoo-case5= free$yahoo%= ? if$c--$dataL5%% ali-case5= case5-case5-0next= ? ptr-0next-ali= ? ? 4ii5 Se,ond Met*od cnode-front= while$cnodeH-(*LL% < if$cnode-0info--data%Ireak= node-node-0next= ? cnode-0next-0prv-cnode-0prv= cnode-0prv-0next-cnode-0next=
free$cnode%=
9include:stdio.h0 9include:conio.h0 9include:alloc.h0 struct node < int info= struct node >left!>right= ?>head= head-$struct node >%malloc$sizeof$struct node%%= head-0left-head-0right-head= head-0info-K=
&'Insertion At 2e%innin%'&
void insert/ eg$% < node >ptr!>temp= int item= prt-$node >Kmalloc$sizeof$node%%= [email protected] the (o1B%= scanf$@CdB!Ditem%= ptr-0info-item= temp-head-0right= head-0right-ptr= ptr-0left-head=
ptr-0right-temp= temp-0left-ptr= ?
&'Insertion At Last'&
void insert/end$% < node >ptr!>temp= int item= ptr-$node >%malloc$sizeof$node%%= scanf$@CdB!Dptr-0info%= temp-head-0left= temp-0right-ptr= ptr-0left-temp= ptr-0right-head= head-0left-ptr= ?
void del/end$% < node >temp= if$head-0right--head%return= else < temp-head-0left= printf$@An3eleted element is Cd AnB!temp-0info%= head-0left-temp-0left= free$temp%= ?
head-temp= cnode-temp= ? else < +. SIR cnode-0next-temp= cnode-cnode-0next= ? printf$@Jress E to continueeeeeee1AnB%= ch-getche$%= ?while$ch--+y+GGch--+E+%= --------------------------------------------------------------------------------------------------------------------------------rear-temp= for$==% < [email protected] co-efficientAnB%= ele-$struct node >%malloc$sizeof$struct node%%= scanf$@CdB!Dcoef%= if$ele-0c--K%Ireak= [email protected] .xponent1AnB%= scanf$@CdB!De%= ele-0expo-e= if$ele-0expo:-K% < printf$@I(;ALI3 I(J*TAnB%= Ireak= ? ele-0next-(*LL= rear-0next-ele= rear-ele= ? temp-temp-0next= ? -----------------------------------------------------------------
+. +OOK
cnode-cnode-0next= ?
ADDITION
The address of 5st Jolynomial is stored in s5 and 6nd Jolynomial is stored in s6. t7-polyadd$s5!s7%= show$t7%= struct poly >polyadd$struct poly >s5!struct poly >s6% < struct poly >s7-K!>p7!>tempo= if$s5--KDDs6--K%return s7= while$s5H--KDDs6H--K% < tempo-$struct poly >%malloc$sizeof$struct poly%%= if$s7--K% < s7-tempo= p7-s7= ? else < p7-0next-tempo= p7-p7-0next= ? if$s5-0expo0s6-0expo% < tempo-0coef-s5-0coef= tempo-0expo-s5-0expo= s5-s5-0next= ? else if$s6-0expo0s5-0expo% < tempo-0coef-s6-0coef= tempo-0expo-s6-0expo= s6-s6-0next= ? else if$s5-0expo--s6-0expo% < tempo-0coef-s5-0coefLs6-0coef= tempo-0expo-s5-0expo= s5-s5-0next= s6-s6-0next= ? ? while$s5H-K% < tempo-$struct node >%malloc$sizeof$struct poly%%= tempo-0coef-s5-0coef= tempo-0expo-s5-0expo= if$s7--K%
< s7-tempo= p7-s7= ? else < p7-0next-tempo= p7-p7-0next= ? s5-s5-0next= ? while$s6H-K% < tempo-$struct poly >%malloc$sizeof$struct node%%= tempo-0coef-s6-0coef= tempo-0expo-s6-0expo= if$s7--K% < s7-tempo= p7-s7= ? else < p7-0next-tempo= p7-p7-0next= ? p7-0next-K= return t7= ?