[데이터 구조] 순서 표 조작 실례
순서 표 (Sequential List) 는 순서대로 저장 하 는 선형 표 로 이 선형 표 의 결산 점 은 논리 적 순서에 따라 컴퓨터 의 연속 적 인 저장 장치 에 순서대로 저장 된다.
순서 표 의 조작 예시 코드 는 다음 과 같다.
package com.company.dataStructure;
import java.util.Scanner;
//       
class DATA {
    String key; //      
    String name;
    int age;
}
class SLType { //       
    static final int MAXLEN = 100;
    DATA[] ListData = new DATA[MAXLEN + 1]; //          
    int ListLen;//          
    void SLInit(SLType SL) { //      
        SL.ListLen = 0;//      
    }
    int SLLength(SLType SL) {
        return (SL.ListLen); //          
    }
    int SLInsert(SLType SL, int n, DATA data) {
        int i;
        if (SL.ListLen >= MAXLEN) { //              
            System.out.print("     ,      !
");
            return 0;
        }
        if (n < 1 || n > SL.ListLen - 1) { //         
            System.out.print("        ,      !
");
            return 0;
        }
        for (i = SL.ListLen; i >= n; i--) { //            
            SL.ListData[i + 1] = SL.ListData[i];
        }
        SL.ListData[n] = data;
        SL.ListLen++;
        return 1;
    }
    int SLAdd(SLType SL, DATA data) { //         
        if (SL.ListLen >= MAXLEN) { //     
            System.out.print("     ,        !
");
            return 0;
        }
        SL.ListData[++SL.ListLen] = data;
        return 1;
    }
    int SLDelete(SLType SL, int n) { //           
        int i;
        if (n < 1 || n > SL.ListLen + 1) {
            System.out.print("        ,      !");
            return 0;
        }
        for (i = n; i < SL.ListLen; i++) { //            
            SL.ListData[i] = SL.ListData[i + 1];
        }
        SL.ListLen--; //        1
        return 1;
    }
    DATA SLFindByNum(SLType SL, int n) { //          
        if (n < 1 || n > SL.ListLen + 1) { //       
            System.out.print("      ,      !
");
            return null;
        }
        return SL.ListData[n];
    }
    int SLFindByCont(SLType SL, String key) { //        
        int i;
        for (i = 1; i < SL.ListLen; i++) {
            if (SL.ListData[i].key.compareTo(key) == 0) { //        
                return i;
            }
        }
        return 0;
    }
    int SLALL(SLType SL) { //           
        int i;
        for (i = 1; i <= SL.ListLen; i++) {
            System.out.printf("(%s, %s ,%d)
", SL.ListData[i].key, SL.ListData[i].name, SL.ListData[i].age);
        }
        return 0;
    }
}
public class SequentList {
    public static void main(String[] args) {
        int i;
        SLType SL = new SLType(); //       
        DATA pdata; //          
        String key; //     
        System.out.print("       !
");
        SL.SLInit(SL);
        System.out.print("        !
");
        Scanner input = new Scanner(System.in);
        do {
            System.out.print("       (        ):");
            DATA data = new DATA();
            data.key = input.next();
            data.name = input.next();
            data.age = input.nextInt();
            if (data.age != 0) { //     0
                if (SL.SLAdd(SL, data) == 0) { //       
                    break;
                }
            } else {
                break; //     
            }
        } while (true);
        System.out.print("
          :
");
        SL.SLALL(SL);
        System.out.print("
        :");
        i = input.nextInt();
        pdata = SL.SLFindByNum(SL, i); //       
        if (pdata != null) {
            System.out.printf(" %d    :(%s,%s,%d)
", i, pdata.key, pdata.name, pdata.age);
        }
        System.out.print("
         :");
        key = input.next();
        i = SL.SLFindByCont(SL, key); //      ,      
        pdata = SL.SLFindByNum(SL, i);
        if (pdata != null) {
            System.out.printf(" %d    :(%s,%s,%d)
", i, pdata.key, pdata.name, pdata.age);
        }
    }
}