Veri Yapıları ve Algoritmalar dönem

Benzer belgeler
Veri Yapıları ve Algoritmalar dönem

Week 6: Bağlı Liste (Linked List) BAĞLI LİSTE KAVRAMI TEKİL (SINGLE) BAĞLI LİSTE ÇİFT (DOUBLE) BAĞLI LİSTE DAİRESEL (CIRCULAR) BAĞLI LİSTE

VERİ YAPILARI LİSTELER. Yrd. Doç. Dr. Murat GÖK Bilgisayar Mühendisliği Bölümü YALOVA ÜNİVERSİTESİ

Final Sınavı Soruları Bahar 2018

Final Sınavı Örnek Soruları Bahar 2018

YZM 2116 Veri Yapıları

Alıştırmalar 2 - Dağıtık Sistemler. Alıştırma 2. Prof. Dr. Th. Letschert Çeviri: Turgay Akbaş FB MNI 16. Mai 2013

Class LinkedList java.lang.object java.util.abstractcollection java.util.abstractlist java.util.abstractsequentiallist java.util.

YMT219 VERİ YAPILARI ÖDEV-1

Nesne tabanlı programlama nesneleri kullanan programlamayı içerir. Bir nesne farklı olarak tanımlanabilen gerçek dünyadaki bir varlıktır.

Cybersoft Bilişim Teknolojileri Sunucu Tarafı Programlaması Kursu Final soruları. Tarih: 27 Kasım 2010 Saat: 13:30 Süre: 3 saat

Arasınav Soruları Bahar 2018

YZM 2116 Veri Yapıları

C++ ile Nesneye Dayalı Programlama

Nesne İşaretçileri. Binnur Kurt Bilgisayar Mühendisliği Bölümü İstanbul Teknik Üniversitesi. Sınıf Yapısı. Kalıtım Çok Şekillilik

Yigin & Kuyruk {\} /\ Suhap SAHIN Onur GÖK

Bölüm 6. Karma. Olcay Taner Yıldız. O. T. Yıldız, C && Java ile Veri Yapılarına Giriş, Boğaziçi Üniversitesi Yayınevi, / 31

Class PriorityQueue. Class PriorityQueue<E> java.lang.object java.util.abstractcollection<e> java.util.abstractqueue<e> java.util.

Yazılım Kodlama ve İ simlendirme Standartları v1.0

Dağıtık Sistemler CS5001

Maltepe Üniversitesi Bilgisayar Mühendisliği Bölümü BİL 203 Veri Yapıları ve Algoritmalar I

Ağaçlar (Trees) Ağaçlar (Trees)

NESNE TABANLI PROGRAMLAMA-1 DERS UYGULAMALARI (22 EYLÜL - 14 KASIM

CharArrayReader. Kılgıladığı Arayüzler: Bildirimi: Değişkenleri (fields): java.io.reader Sınıfından Kalıtsal Gelen Değişken:

BİL132 Bilgisayar Programlama II

Spring Framework Eğitimi

Upgrading Internet Technology skills of Information and Communication Technologies (ICT) Professionals

Bölüm 8. Ayrık Küme. Olcay Taner Yıldız. O. T. Yıldız, C && Java ile Veri Yapılarına Giriş, Boğaziçi Üniversitesi Yayınevi, / 16

VERİ YAPILARI DERS NOTLARI BÖLÜM 1 GİRİŞ. Yard. Doç. Dr. Deniz KILINÇ

Stack Islemleri. Postfix ve Infix notasyonlari. Stack ozellikleri

ArrayList Uygulamaları

Java da, tüm değişkenlerin kullanılmadan önce tanımlanması edilmesi gerekir. Bir değişken tanımlamanın temel gösterimi bu şekildedir:

KUYRUKLAR QUEUES. Doç. Dr. Aybars UĞUR

BAĞLAÇLI LİSTELER LINKED LISTS

Dağıtık Sistemler CS5001

Chain of Responsibility Tasarım Şablonu KurumsalJava.com

BAĞLAÇLI LİSTELER LINKED LISTS

Şablon Türler (Generics)

1. Aşağıdaki program parçacığını çalıştırdığınızda result ve param değişkenlerinin aldığı en son değerleri ve programın çıktısını yazınız.

Week 7. Düğüm bulma Tekli bağlı liste: phead ve ptail Dairesel bağlı liste Çift bağlı liste

D-Link DSL 500G için ayarları

Oyun Programlama. Tasarım Örüntüleri

const objects & const member functions const objects ve const functions Data Member Initializer List Data Member Initializer List

int main(void) { int num = 0; int input = 1; int retval = 0; struct NODE *nodepointer; nodepointer = (struct NODE *)malloc(sizeof(struct NODE));

DATA STRUCTURES. Part III. Sınıflar, Nesneler ve İlgili Programlama Örnekleri

VERİ YAPILARI DERS NOTLARI BÖLÜM 5 QUEUE (KUYRUK) Yard. Doç. Dr. Deniz KILINÇ

BBS 514 YAPISAL PROGRAMLAMA (STRUCTURED PROGRAMMING)

BMH-303 Nesneye Yönelik Programlama

BBS 514 YAPISAL PROGRAMLAMA (STRUCTURED PROGRAMMING)

BAĞLI LİSTELER BAĞLI LİSTELER

Đlgili konular: Collection, Set, HashSet, Comparable, Comparator, TreeMap, Collections.synchronizedSortedSet(SortedSet), Serialized Form

Binary Search. (Yarılama) Bölüm Dizide Bir Öğe Arama

Görsel Programlama DERS 03. Görsel Programlama - Ders03/ 1

Yığıtın en üstündeki öğeyi değer olarak alır; ama onu yığıttan almaz, yerinde bırakır.

Kaynak Kod Güvenliği Bir Güvensiz API Örneği

/*Aşağıda ki kodları doğru şekilde anlar ve kullanırsanız java da sınıfları biraz da olsa anlamış olursunuz.*/

SOMEBODY ELSE'S. ( DATA STRUCTURES and ALGORITHMS ) Veri Yapıları ve Algoritmaları

TEMPLATES. Binnur Kurt Bilgisayar Mühendisliği Bölümü İstanbul Teknik Üniversitesi. C++ ile Nesneye Dayalı Programlama 1

Nesneye Dayalı Programlama

Alıştırma 1: Yineleme

Bölüm 24. Java Ağ Uygulamaları 24.1 Java Appletleri. Bir Applet in Yaşam Döngüsü:

1 JAVASCRIPT NEDİR? 1

AĞAÇLAR TREES. Doç. Dr. Aybars UĞUR

Lab7 DOĞU AKDENİZ ÜNİVERSİTESİ BİLGİSAYAR VE TEKNOLOJİ YÜKSEKOKULU BİLGİSAYAR PROGRAMCILIĞI. BTEP212 Java. Uygulama1: package javaapplication58;

Algoritmalar. İkili Arama Ağaçları. Bahar 2016 Doç. Dr. Suat Özdemir 1

Standard Template Library

const objects & const member functions

Object-Oriented Programming Laboratuvar 11

Pros and Cons of Pointers. Pointers. Avantajlar. Dezavantajlar

«BM364» Veritabanı Uygulamaları

BLM401 Mobil Cihazlar için ANDROID İşletim Sistemi. SQLite Veritabanı. BLM401 Dr.Refik SAMET

ByteArrayOutputStream

YIĞIT STACK. Yrd. Doç. Dr. Aybars UĞUR

Java da İşleçler, Ders #3 (4 Kasım 2009)

AĞAÇLAR. Doç. Dr. Aybars UĞUR

Bire-bir Sahiplik İlişkisi ile İlgili Sorular:

Java dili, aşağıdakiler de dahil olmak üzere çok çeşitli denetleyici türlerine sahiptir.

SIRALAMA SORTING. Doç. Dr. Aybars UĞUR

İçerik. Java da İşleçler, İşleçler. Aritmetik İşleçler - 1. Aritmetik İşleçler - 2. Geçen ders: Bu ders: BS-515 Nesneye Yönelik Programlama

NESNEYE DAYALI PROGRAMLAMA 9. HAFTA UYGULAMA DERSİ

CENG/BILM 341 FINAL REVIEW. Dr. Esma Yıldırım

Kılgıladığı arayüzler: Serializable, Cloneable, Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

ASP.NET CLASS KULLANARAK VERİTABANI İŞLEMLERİ

İl İlçe uygulaması. : Seçilen ile ait ilçeleri listeleyen program. //İl değişkeni için kodu aşağıdaki sayfadan kopyalayınız.

MOBIL UYGULAMA GELIŞTIRME

Java Programlama Dilinde Veri Tipleri. Yrd. Doç. Dr. Aybars UĞUR

Arayüz soyut metotların oluşturduğu bir koleksyondur. Bir sınıf arayüzü çalıştırırken arayüzün sahip olduğu soyut metotları da miras alır.

BMH-303 Nesneye Yönelik Programlama

Interface Comparator. Kılgılayan sınıf: Collator. Bildirimi: public interface Comparator

Bir c sınıfının doğal sıralaması ile tutarlı olması (be consistent with equals) demek, c sınıfı içindeki her e1 ve e2 nesnesi için

Unlike analytical solutions, numerical methods have an error range. In addition to this

Burak Kıymaz JAVA FX

MAT214 BİLGİSAYAR PROGRAMLAMA II DERSİ Ders 11: Sınıf (Class) Yapıları (Örnekler)

Java, java.util paketi içinde mevcut olan Date sınıfını sağlar, bu sınıf güncel tarih ve zamanı kapsüllemektedir.

BMÜ-111 Algoritma ve Programlama. Bölüm 5. Tek Boyutlu Diziler

Merge (Bireşim) Algoritmayı önce bir örnek üzerinde açıklayalım.

C#.Net & Linq (Language Integrated Query)

Class HashSet. Metotlar. Class HashSet java.lang.object java.util.abstractcollection java.util.abstractset java.util.hashset

Week 9: Trees 1. TREE KAVRAMI 3. İKİLİ AĞAÇ DİZİLİMİ 4. İKİLİ ARAMA AĞACI 2. İKİLİ AĞAÇ VE SUNUMU > =

C++ Class larina baslangic. C++ Versus C Object-oriented Language C++ Structure dan Object Create etmek. Structure tanimlama.

Transkript:

Veri Yapıları ve Algoritmalar 2006-2007 2.dönem Bağlantılı Listeler Derste kullanılan kodlar

Bağlantılı liste (tek yönlü) head next null

/** Node of a singly linked list of strings. */ public class Node { private String element; // we assume elements are character strings private Node next; /** Creates a node with the given element and next node. */ public Node(String s, Node n) { element = s; next = n; /** Returns the element of this node. */ public String getelement() { return element; /** Returns the next node of this node. */ public Node getnext() { return next; // Modifier methods: /** Sets the element of this node. */ public void setelement(string newelem) {element = newelem; /** Sets the next node of this node. */ public void setnext(node newnext) { next = newnext;

/** Singly linked list.*/ public class SLinkedList { protected Node head; // head node of the list /** Default constructor that creates an empty list */ public SLinkedList() { head = null; //... update and search methods would go here...

public void AddFirst(Node newnode){ Node n=new Node(newnode.getElement(),null); n.setnext(head); head=n;

public Node getlast(node listhead){ Node last=listhead; if(last!=null){ while(last.getnext()!=null){ last=last.getnext(); return last;

public void AddLast(Node newnode){ Node n=new Node(newnode.getElement(),null); if(getlast(head)!=null){ getlast(head).setnext(n); else{ head=n;

public String tostring(){ String s="["; Node temp=head; while(temp!=null){ s+=temp.getelement(); if(temp.getnext()!=null){ s+=","; temp=temp.getnext(); s+="]"; return s;

public void removefirst(){ if(head==null){ System.out.println("Empty list"); return; Node temp=head; head=head.getnext(); temp.setnext(null);

public void removelast(){ if(head==null){ System.out.println("Empty list"); return; Node temp=head; if(temp.getnext()==null){//list with one element head=null; return; while(temp.getnext().getnext()!=null){ temp=temp.getnext(); temp.setnext(null);

public void removespecific(int i){ int k=1; Node temp=head; Node previous=temp; while(temp!=null && k<i){ previous=temp; temp=temp.getnext(); k++; if(i==1){ removefirst(); else if(temp==null){ System.out.println("index out of range"); else{ previous.setnext(temp.getnext()); temp.setnext(null);

public void addspecific(int i, Node newnode){ //smaller than 1, at the beginning if(i<=1 head==null){ AddFirst(newnode); return; //larger than the list size, at the end Node n=new Node(newnode.getElement(),null); int k=1; Node previous=head; while(previous.getnext()!=null && k<i-1){ previous=previous.getnext(); k++; n.setnext(previous.getnext()); previous.setnext(n);

Bağlantılı liste (çift yönlü) head next previous tail

/** Node of a doubly linked list of strings */ public class DNode { protected String element; // String element stored by a node protected DNode next, prev; // Pointers to next and previous nodes /** Constructor that creates a node with given fields */ public DNode(String e, DNode p, DNode n) { element = e; prev = p; next = n; /** Returns the element of this node */ public String getelement() { return element; /** Returns the previous node of this node */ public DNode getprev() { return prev; /** Returns the next node of this node */ public DNode getnext() { return next; /** Sets the element of this node */ public void setelement(string newelem) { element = newelem; /** Sets the previous node of this node */ public void setprev(dnode newprev) { prev = newprev; /** Sets the next node of this node */ public void setnext(dnode newnext) { next = newnext;

/** Doubly linked list with nodes of type DNode storing strings. */ public class DList { protected int size; // number of elements protected DNode header, trailer; // sentinels /** Constructor that creates an empty list */ public DList() { size = 0; header = new DNode(null, null, null); // create header trailer = new DNode(null, header, null); // create trailer header.setnext(trailer); // make header and trailer point to each other..

/** Returns the number of elements in the list */ public int size() { return size; /** Returns whether the list is empty */ public boolean isempty() { return (size == 0); /** Returns the first node of the list */ public DNode getfirst() throws IllegalStateException { if (isempty()) throw new IllegalStateException("List is empty"); return header.getnext(); /** Returns the last node of the list */ public DNode getlast() throws IllegalStateException { if (isempty()) throw new IllegalStateException("List is empty"); return trailer.getprev();

/** Returns the node before the given node v. An error occurs if v * is the header */ public DNode getprev(dnode v) throws IllegalArgumentException { if (v == header) throw new IllegalArgumentException ("Cannot move back past the header of the list"); return v.getprev(); /** Returns the node after the given node v. An error occurs if v * is the trailer */ public DNode getnext(dnode v) throws IllegalArgumentException { if (v == trailer) throw new IllegalArgumentException ("Cannot move forward past the trailer of the list"); return v.getnext();

/** Inserts the given node z before the given node v. An error * occurs if v is the header */ public void addbefore(dnode v, DNode z) throws IllegalArgumentException { DNode u = getprev(v); // may throw an IllegalArgumentException z.setprev(u); z.setnext(v); v.setprev(z); u.setnext(z); size++;

/** Inserts the given node z after the given node v. An error occurs * if v is the trailer */ public void addafter(dnode v, DNode z) { DNode w = getnext(v); z.setprev(v); z.setnext(w); w.setprev(z); v.setnext(z); size++;

/** Inserts the given node at the head of the list */ public void addfirst(dnode v) { addafter(header, v); /** Inserts the given node at the tail of the list */ public void addlast(dnode v) { addbefore(trailer, v);

/** Removes the given node v from the list. An error occurs if v is * the header or trailer */ public void remove(dnode v) { DNode u = getprev(v); DNode w = getnext(v); // unlink the node from the list w.setprev(u); u.setnext(w); v.setprev(null); v.setnext(null); size--;

/** Returns whether a given node has a previous node */ public boolean hasprev(dnode v) { return v!= header; /** Returns whether a given node has a next node */ public boolean hasnext(dnode v) { return v!= trailer; / ** Returns a string representation of the list */ public String tostring() { String s = "["; DNode v = header.getnext(); while (v!= trailer) { s += v.getelement(); v = v.getnext(); if (v!= trailer) s += ","; s += "]"; return s;

Bağlantılı listede sıralama Çift yönlü bir bağlantılı listede eklemeli sıralama head next previous tail

/** Insertion-sort for a doubly linked list of class DList. */ public static void sort(dlist L) { if (L.size() <= 1) return; // L is already sorted in this case DNode pivot; // pivot node DNode ins; // insertion point DNode end = L.getFirst(); // end of run while (end!= L.getLast()) { pivot = end.getnext(); // get the next pivot node L.remove(pivot); // remove it ins = end; // start searching from the end of the sorted run while (L.hasPrev(ins)&&ins.getElement().compareTo(pivot.getElement()) > 0) ins = ins.getprev(); // move left L.addAfter(ins,pivot); // add the pivot back, after insertion point if (ins == end) // we just added pivot after end in this case end = end.getnext(); // so increment the end marker