'Array List'에 해당되는 글 1건

  1. 2009.06.02 [C#] Collections (1)

[C#] Collections (1)

Programming/.NET Programming 2009. 6. 2. 15:43

Collections 용어 정리


      Collection : 데이터 보관 가능 수정, 삭제 삽입의 기능을 가지고 있음
      ex. *(원형)Linked List, *Stack, *Queue, *List, Array List, Hash, Hash Table 등


      1. Linked List : 노드와 노드 간이 포인터로 연결되어 있어서 노드 간 검색이 가능

      2. Array List :  List와 거의 흡사, List와 구분이 되는 것은 자료형을 따지지 않는 점.
                        노드간의 다른 자료형을 넣을 수 있음. 편하지만 용량을 많이 차지.

      3. List : 사용법은 1차원 배열과 같음,
                Stack, Queue, Linked List의 모든 단점을 보완할 수 있음,
                노드간 검색 가능하고 Stack, Queue의 모든 기능을 소화함.
                넣을 때 insert, 뺄 때 remove
                원하는 인덱스에 넣고 뺄 수 있음(Stack, Queue 대신 이걸 더 많이 씀)

      4. Stack : 넣을 때 push, 뺄 때 pop, LIFO

      5. Queue : 넣을 때 enqueue, 뺄 때 dequeue, FIFO 

      6. Hash : 넓은 범위의 것을 좁게 접근, 인덱스를 가지고 있음.
                  각각 node에 key값과 value값을 가짐.
                  value에 접근할 때 key로 접근이 가능함


      - 배열과 Collection의 가장 큰 차이점 : 정적 - 동적의 차이

 


Linked List 사용 예제

using System;
// LinkedList를 구현하기 위해 추가적으로 필요한 namespace
using System.Collections;
using System.Collections.Generic;

namespace LinkedList

{

    class Program

    {

        static void Main(string[] args)

        {

            int cnt;

            int input = 0;

           

            LinkedList<int> list = new LinkedList<int>(); // Linked List 생성

            LinkedListNode<int> plist; // Linked List Node 생성

           

            ///////////////////////////////////////////////////////////////////////////////////

            //

            //    Linked List Node : Linked에 대한 참조(연결정보를 담고 있음)

            //

            ///////////////////////////////////////////////////////////////////////////////////

           

            Console.Write("몇 개의 데이터를 저장하실건가요? ");

            cnt = int.Parse(Console.ReadLine()); // string값을 int형으로 읽어옴

 

            Console.WriteLine("\n---------------입력---------------");

 

            for (int i = 0; i < cnt; i++)

            {

                Console.Write(i+1 + "번째 데이터를 입력해주세요 : ");

                input = int.Parse(Console.ReadLine()); // string값을 int형으로 읽어옴

                list.AddLast(input); // Linked List에 값을 추가

            }

 

            Console.WriteLine("----------------------------------");

            Console.WriteLine("\n---------------출력---------------");

 

            plist = list.First; // ListNode List의 첫번째 Node 연결정보를 가져옴.

            for (int i = 0; i < list.Count; i++)

            {

                Console.WriteLine(i+1 + "번째 노드에 저장된 데이터 값 : " 
                                                                 + plist.Value);
// Data
를 읽어옴

                plist = plist.Next; // 다음 Node의 연결정보를 가져옴.

            }

            Console.WriteLine("----------------------------------");

        }

    }

}     

 

 


Array List 사용 예제

using System;

using System.Collections; // ArrayList를 구현하기 위해 추가적으로 필요한 namespace

 

namespace ArrayList

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList list = new ArrayList(); // Array List 생성, 자료형 따지지 않음

 

            int z = 0 ;

            float j = 1.5f;

            double k = 2.3;

 

            list.Add(z); // Data 추가

            list.Add(j); // Data 추가

            list.Add(k); // Data 추가

 

            for(int i = 0 ; i< list.Count; i++)

                 Console.WriteLine(list[i]); // Data 출력

          }

     }

}

 

 

 


 


'Programming > .NET Programming' 카테고리의 다른 글

[C#] Collections (2)  (0) 2009.09.15
[C#] Collections (3)  (0) 2009.06.02
[C#] Enum과 배열  (0) 2009.05.31
[C#] this와 상속  (0) 2009.05.31
[C#] 오버로딩과 오버라이딩  (0) 2009.05.31
: