diff options
Diffstat (limited to '659/CH13/EX2.cs/Casestudy2.sci')
-rwxr-xr-x | 659/CH13/EX2.cs/Casestudy2.sci | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/659/CH13/EX2.cs/Casestudy2.sci b/659/CH13/EX2.cs/Casestudy2.sci new file mode 100755 index 000000000..995b81830 --- /dev/null +++ b/659/CH13/EX2.cs/Casestudy2.sci @@ -0,0 +1,68 @@ +// Case Study: Chapter:13 ,Page No.:438
+// 2.Building a Sorted List
+
+funcprot(0);
+//Create the list
+function [List]=create(list1)
+ global List;
+ // Create the current node
+ list1.number=input("Input a number(Type -999 to end); ");
+ if list1.number==-999 then
+ list1.next=NULL;
+ list1.add=NULL;
+ else
+ list1.add=list1.add+1;
+ list1.next=NULL;
+ List(i)=list1;
+ if(i==1) then
+
+ else
+ List(i-1).next=List(i).add
+ end
+ i=i+1;
+ create(list1);// Create the next node
+ end
+ return;
+endfunction
+function []=print1(list1)
+ if list1(i)(1).next~=NULL then
+ printf("%d--->",list1(i)(1).number);//Print current item
+ i=i+1;
+ if list1(i)(1).next==NULL then
+ printf("%d",list1(i)(1).number);
+ end
+ print1(list1);//Move to next item
+ end
+ return;
+endfunction
+//Sorting of the numbers in the list
+function [List]=insert_sort(list1)
+ global List;
+ j=1;
+ while (list1(j)(1).next~=NULL)
+ i=1;
+ while (list1(i)(1).next~=NULL)
+ if(list1(i)(1).number >list1(i+1)(1).number) then
+ temp=list1(i)(1).number;
+ list1(i)(1).number=list1(i+1)(1).number;
+ list1(i+1)(1).number=temp;
+ end
+ i=i+1;
+ end
+ j=j+1;
+ end
+ List=list1;
+endfunction
+
+global List;
+NULL=0;i=1;
+//Create the structure i.e. node
+node=struct('number',0,'add',0,'next',0);
+head=node;
+//Calling the functions
+List=create(head);
+printf("\nOriginal List: ");
+print1(List);
+List=insert_sort(List); //Sort the list
+printf("\nAfter sorting: ");
+print1(List);
\ No newline at end of file |