summaryrefslogtreecommitdiff
path: root/659/CH13/EX13.5/exm13_5.sci
blob: c23558f6c5ec647e6f3f4e363234413ddd9696b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//                    Example 13.5
//Write a program/function to delete a specified node.

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); ")//scanf("%d");
    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 to print the numbers of list
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
//Function to delete the specified node
function [List]=delet(list1)
    key=input("Value of item number to be deleted?");//Read value of key
    //Find and delete the key node
    while(list1(i)(1).number~=key) then
        if list1(i)(1).next==NULL then
            printf("Item not found in the list");
            return;
        end
        i=i+1;
     end
     while(list1(i).next~=NULL)
         list1(i)(1).number=list1(i+1)(1).number;
         i=i+1;
     end
     list1(i-1)(1).next=NULL;
     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=delet(List);
printf("\nAfter deletion List is: ");
print1(List)