diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /1034/CH4 | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '1034/CH4')
-rwxr-xr-x | 1034/CH4/EX4.1/4s1.sce | 7 | ||||
-rwxr-xr-x | 1034/CH4/EX4.2/4s2.sce | 158 | ||||
-rwxr-xr-x | 1034/CH4/EX4.3/4s3.sce | 95 | ||||
-rwxr-xr-x | 1034/CH4/EX4.4/4s4.sce | 168 |
4 files changed, 428 insertions, 0 deletions
diff --git a/1034/CH4/EX4.1/4s1.sce b/1034/CH4/EX4.1/4s1.sce new file mode 100755 index 000000000..01926a165 --- /dev/null +++ b/1034/CH4/EX4.1/4s1.sce @@ -0,0 +1,7 @@ +//List of words in a linked list.
+clear;
+clc;
+printf("\n Exapmle 4.1\n");
+x=list('sci','lab','text','companionship','project');
+disp("x=");
+disp(x);
diff --git a/1034/CH4/EX4.2/4s2.sce b/1034/CH4/EX4.2/4s2.sce new file mode 100755 index 000000000..b6a2abefd --- /dev/null +++ b/1034/CH4/EX4.2/4s2.sce @@ -0,0 +1,158 @@ +//CIRCULAR LINKED LIST
+clear;
+clc;
+funcprot(0);
+disp("Example 4.2");
+function[link2]=append(ele,link1)
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ if(link1(1)(1).add==0)
+ link1(1)(1).data=ele;
+ link1(1)(1).add=1;
+ link1(1)(1).nexadd=1;
+ link2(1)=link1(1)(1);
+ else
+ if(link1(1)(1).nexadd==link1(1)(1).add)
+ lin2=link1(1)(1);
+ lin2.data=ele;
+ lin2.add=link1(1)(1).add+1;
+ link1(1)(1).nexadd=lin2.add;
+ lin2.nexadd=link1(1)(1).add;
+ link2(1)=link1(1)(1);
+ link2(2)=lin2;
+ else
+ lin2=link1(1)(1);
+ i=1;
+ while(link1(i)(1).nexadd~=link1(1)(1).add)
+ i=i+1;
+ end
+ j=i;
+ lin2.data=ele;
+ lin2.add=link1(i).add+1;
+ lin2.nexadd=link1(1)(1).add;
+ link1(i).nexadd=lin2.add;
+ link2(1)=link1(1)(1);
+ i=2;
+ while(link1(i).nexadd~=lin2.add)
+ link2(i)=(link1(i));
+ i=i+1;
+ end
+ link2(i)=link1(i);
+ link2(i+1)=lin2;
+ end
+ end
+endfunction
+function[link2]=add(ele,pos,link1);
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ i=1;
+ while(i<=pos)
+ if(link1(i).nexadd==link1(1)(1).add)
+ break;
+ else
+ i=i+1;
+ end
+ end
+ if(link1(i).nexadd~=link1(1)(1).add)
+ i=i-1;
+ lin2.data=ele;
+ lin2.add=i;
+ j=i;
+ while(link1(j).nexadd~=link1(1)(1).add)
+ link1(j).add=link1(j).add+1;
+ link1(j).nexadd=link1(j).nexadd+1;
+ j=j+1;
+ end
+ link1(j).add=link1(j).add+1;
+ lin2.nexadd=link1(i).add;
+ link1(i-1).nexadd=lin2.add;
+ k=1;
+ while(k<i)
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ link2(k)=lin2;
+ k=k+1;
+ link2(k)=link1(k-1);
+ k=k+1
+ l=k-1;
+ while(k~=j)
+ link2(k)=link1(l);
+ k=k+1;
+ l=l+1;
+ end
+ link2(j)=link1(j-1);;
+ link2(j+1)=link1(j);
+ else
+ if(i==pos)
+ k=1;
+ lin2.data=ele;
+ lin2.add=link1(i-1).add+1;
+ link1(i).add=link1(i).add+1;
+ lin2.nexadd=link1(i).add;
+ link1(i).nexadd=link1(1)(1).add;
+ k=1;
+ while(k<pos)
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ link2(k)=lin2;
+ link2(k+1)=link1(k)
+ end
+ end
+
+endfunction
+function[link2]=delete1(pos,link1)
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ i=1;
+ j=1;
+ while(i<pos)
+ if((link1(j).nexadd==link1(1)(1).add))
+ j=1;
+ i=i+1;
+ else
+ i=i+1;
+ j=j+1;
+ end
+ end
+ if(link1(j).nexadd~=link1(1)(1).add)
+ k=1;
+ if(j==1)
+ k=2;
+ while(link1(k).nexadd~=link1(1)(1).add)
+ link2(k-1)=link1(k);
+ k=k+1;
+ end
+ link2(k-1)=link1(k);
+ link2(k-1).nexadd=link2(1).add;
+ else
+ lin2=link1(j);
+ link1(j-1).nexadd=link1(j+1).add;
+ k=1;
+ while(link1(k).nexadd~=link1(j+1).add)
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ link2(k)=link1(k);
+ k=k+2;
+ while(link1(k).nexadd~=link1(1)(1).add)
+ link2(k-1)=link1(k);
+ k=k+1;
+ end
+ link2(k-1)=link1(k);
+ end
+ else
+ link1(j-1).nexadd=link1(1)(1).add;
+ l=1;
+ while(link1(l).nexadd~=link1(1)(1).add)
+ link2(l)=link1(l);
+ l=l+1;
+ end
+ link2(l)=link1(l);
+ end
+endfunction
+//Calling Routine:
+link1=struct('data',0,'add',0,'nexadd',0);
+link1=append(4,link1);//This will actualy create a list and 4 as start
+link1=append(6,link1);
+link1=add(10,2,link1);
+link1=delete1(4,link1);//As the list is circular the 4'th element refers to actualy the 1'st one
+disp(link1,"After the above manuplations the list is");
\ No newline at end of file diff --git a/1034/CH4/EX4.3/4s3.sce b/1034/CH4/EX4.3/4s3.sce new file mode 100755 index 000000000..c8d391a15 --- /dev/null +++ b/1034/CH4/EX4.3/4s3.sce @@ -0,0 +1,95 @@ +//List Insertion.
+clc;
+clear;
+disp("Example 4.3");
+funcprot(0)
+function[link2]=insert_pri(ele,link1)
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ if(link1(1)(1).add==0)
+ link1(1)(1).data=ele;
+ link1(1)(1).add=1;
+ link1(1)(1).nexadd=1;
+ link2(1)=link1(1)(1);
+ else
+ if(link1(1)(1).nexadd==link1(1)(1).add)
+ if(ele>=link1(1)(1).data)
+ t=ele;
+ p=link1(1)(1).data;
+ else
+ t=link1(1)(1).data;
+ p=ele;
+ end
+ link1(1)(1).data=t;
+ lin2=link1(1)(1);
+ lin2.data=p;
+ lin2.add=2;
+ lin2.nexadd=link1(1)(1).add;
+ link1(1)(1).nexadd=lin2.add;
+ link2(1)=link1(1)(1);
+ link2(2)=lin2;
+ else
+ i=1;
+ a=[];
+ while(link1(i).nexadd~=link1(1)(1).add)
+ a=[a(:,:) link1(i).data];
+ i=i+1;
+ end
+ a=[a(:,:) link1(i).data];
+ a=gsort(a);
+ j=1;
+ while(j<=i)
+ link1(j).data=a(j);
+ j=j+1;
+ end
+ k=1;
+ while(link1(k).data>=ele)
+ if(link1(k).nexadd==link1(1)(1).add)
+ break;
+ else
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ end
+ if(link1(k).nexadd~=link1(1)(1).add)
+ lin2=link1(k);
+ lin2.data=ele;
+ lin2.add=link1(k).add;
+ j=k;
+ y=link1(1)(1).add;
+ while(link1(k).nexadd~=y)
+ link1(k).add=link1(k).add+1;
+ link1(k).nexadd=link1(k).nexadd+1;
+ k=k+1;
+ end
+ link1(k).add=link1(k).add+1;
+ lin2.nexadd=link1(j).add;
+ link2(j)=lin2;
+ j=j+1;
+ while(j<=k+1)
+ link2(j)=link1(j-1);
+ j=j+1;
+ end
+ else
+ lin2=link1(k);
+ lin2.data=ele;
+ lin2.nexadd=link1(1)(1).add;
+ lin2.add=link1(k).add+1;
+ link1(k).nexadd=lin2.add;
+ j=1;
+ while(j<=k)
+ link2(j)=link1(j);
+ j=j+1;
+ end
+ link2(j)=lin2;
+ end
+ end
+ end
+ endfunction
+ //Calling Routine:
+ link1=struct('data',0,'add',0,'nexadd',0);
+ link1=insert_pri(3,link1);
+ link1=insert_pri(4,link1);
+ link1=insert_pri(22,link1);
+ link1=insert_pri(21,link1);
+ link1=insert_pri(11,link1);
+ disp(link1,"List After Insertions");
\ No newline at end of file diff --git a/1034/CH4/EX4.4/4s4.sce b/1034/CH4/EX4.4/4s4.sce new file mode 100755 index 000000000..cf9890d00 --- /dev/null +++ b/1034/CH4/EX4.4/4s4.sce @@ -0,0 +1,168 @@ +//Deletion from the list:
+function[link2]=append(ele,link1)
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ if(link1(1)(1).add==0)
+ link1(1)(1).data=ele;
+ link1(1)(1).add=1;
+ link1(1)(1).nexadd=0;
+ link1(1)(1).prevadd=0;
+ link2(1)=link1(1)(1);
+ else
+ if(link1(1)(1).nexadd==0)
+ lin2=link1(1)(1);
+ lin2.data=ele;
+ lin2.add=link1(1)(1).add+1;
+ link1(1)(1).nexadd=lin2.add;
+ lin2.nexadd=0;
+ lin2.prevadd=link1(1)(1).add;
+ link2(1)=link1(1)(1);
+ link2(2)=lin2;
+ else
+ lin2=link1(1)(1);
+ i=1;
+ while(link1(i)(1).nexadd~=0)
+ i=i+1;
+ end
+ j=i;
+ lin2.data=ele;
+ lin2.add=link1(i).add+1;
+ lin2.nexadd=0;
+ link1(i).nexadd=lin2.add;
+ lin2.prevadd=link1(i).add;
+ link2(1)=link1(1)(1);
+ i=2;
+ while(link1(i).nexadd~=lin2.add)
+ link2(i)=(link1(i));
+ i=i+1;
+ end
+ link2(i)=link1(i);
+ link2(i+1)=lin2;
+ end
+ end
+endfunction
+function[link2]=add(ele,pos,link1);
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ i=1;
+ while(i<=pos)
+ if(link1(i).nexadd==0)
+ break;
+ else
+ i=i+1;
+ end
+ end
+ if(link1(i).nexadd~=0)
+ i=i-1;
+ lin2.data=ele;
+ lin2.add=i;
+ j=i;
+ while(link1(j).nexadd~=0)
+ link1(j).prevadd=link1(j).prevadd+1;
+ link1(j).add=link1(j).add+1;
+ link1(j).nexadd=link1(j).nexadd+1;
+ j=j+1;
+ end
+ link1(j).prevadd=link1(j).prevadd+1;
+ link1(j).add=link1(j).add+1;
+ lin2.nexadd=link1(i).add;
+ link1(i).prevadd=lin2.add;
+ lin2.prevadd=link1(i-1).add;
+ link1(i-1).nexadd=lin2.add;
+ k=1;
+ while(k<i)
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ link2(k)=lin2;
+ k=k+1;
+ link2(k)=link1(k-1);
+ k=k+1
+ l=k-1;
+ while(k~=j)
+ link2(k)=link1(l);
+ k=k+1;
+ l=l+1;
+ end
+ link2(j)=link1(j-1);;
+ link2(j+1)=link1(j);
+ else
+ if(i==pos)
+ k=1;
+ lin2.data=ele;
+ lin2.add=link1(i-1).add+1;
+ link1(i).add=link1(i).add+1;
+ lin2.nexadd=link1(i).add;
+ link1(i).prevadd=lin2.add;
+ lin2.prevadd=link1(i-1).add;
+ k=1;
+ while(k<pos)
+ link2(k)=link1(k);
+ k=k+1;
+ end
+ link2(k)=lin2;
+ link2(k+1)=link1(k)
+ end
+ end
+
+endfunction
+function[link2]=delete1(pos,link1)
+ link2=list(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0);
+ i=1;
+ while(i<=pos)
+ if((link1(i).nexadd==0))
+ break;
+ else
+ i=i+1;
+ end
+ end
+ if(link1(i).nexadd~=0)
+ i=i-1;
+ j=1;
+ if(i==1)
+ j=1;
+ while(link1(j).nexadd~=0)
+ link2(j)=link1(j);
+ j=j+1;
+ end
+ link2(j)=link1(j);
+ else
+ link1(i-1).nexadd=link1(i+1).add;
+ link1(i+1).prevadd=link1(i-1).add;
+ while(link1(j).nexadd~=link1(i+1).add)
+ link2(j)=link1(j);
+ j=j+1;
+ end
+ if(j~=i-1)
+ link2(j)=link1(j);
+ link2(j+1)=link1(j+1);
+ k=i+1;
+ l=2;
+ else
+ link2(j)=link1(j);
+ k=i+1;
+ l=1;
+ end
+ while(link1(k).nexadd~=0)
+ link2(j+l)=link1(k);
+ k=k+1;
+ l=l+1;
+ end
+ link2(j+l)=link1(k);
+ end
+ else
+ if(i==pos)
+ j=1;
+ link1(i-1).nexadd=0;
+ while(j<=i-1)
+ link2(j)=link1(j);
+ j=j+1;
+ end
+ end
+ end
+endfunction
+//Calling Routine:
+link1=struct('data',0,'add',0,'nexadd',0);
+link1=append(4,link1);
+link1=append(6,link1);
+link1=add(10,2,link1);
+link1=delete1(3,link1);
+disp(link1,"After the above manipulation the list is");
\ No newline at end of file |