SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
Prog_2 course- 2014 
2 bytes team 
Kinan keshkeh 
IT Engineering-Damascus University 
3rd year
Single linked 
list 
Locomotive and trailer
Why linked list ? 
When we deal with arrays sometimes we are exposed to the problem is ((constant Reservation in memory )) 
That means the size of the array already constant and we can’t change it in program 
We can use pointer to set up data structure 
Similar array but it allows us to change their size in the program during execution 
This data structure is named ((linked list))
Linked list are divided into : 
Single linked list 
Double linked list 
Circular linked list 
In the second year
Single linked list : 
list is elements of record type one of it fields pointer on another record 
Consists of a list of elements that are arranged where each element is assigned with the following element- with pointer, as in the following example: 
Definition : 
p 
type 
type 
type 
type 
nil 
H 
d 
u 
a 
<type>; 
char 
integer 
11 
10 
22 
7 
Type ptr=^node; 
node = record ; 
Key : 
next : ptr; 
end ; 
Var p : ptr;
Create list : 
We can create a single linked list of two ways : 
From the last node to the first one(FILO) 
1 
4 multiples 
Ex : 
Write procedure to create single linked list include Multiples number (3) Limited within the domain of 1 to 14, where the list is building from the last node to the first one 
4 nodes 
numbers are { 3,6,9,12 } 
Type ptr=^node 
Node=record 
Key : integer ; 
Next : ptr ; 
End ;
Procedure create1(var p1:ptr); 
Var temp: ptr; x,i : integer; 
Begin 
for i:=1 to 4 do 
begin 
end ; 
End ; 
p1:=nil; 
x:=3; 
new ( temp ); 
temp^.key :=x; 
temp^.next := p1 ; 
p1 := temp; 
x := x+3; 
x 
i 
p1 
Nil 
next 
Nil 
temp 
12 
3 
1 
9 
p1 
3 
p1 
6 
12 
6 
3 
2 
9 
temp 
p1 
4 
temp 
temp 
p1
Create list : 
From the first node to the last one (FIFO) : 
2 
Ex : 
Write procedure to create single linked list include Multiples number (5) Limited within the domain of 1 to 20, where the list is building from the first node to the last one 
Procedure create2( var p2 :ptr ); 
Var temp:ptr; x,i : integer; 
Begin 
x :=5; 
new(p2); 
p2.key:=x; 
temp:=p2; 
For i:=2 to 4 do 
Begin 
new (temp^.next); 
temp:= temp^.next; 
x:=x+5; 
temp^.key:=x; 
end; 
temp^.next :=nil; 
End ;
Procedure create2( var p2 :ptr ); 
Var temp:ptr; x,i : integer; 
Begin 
For i:=2 to 4 do 
Begin 
temp:= temp^.next; 
x:=x+5; 
end; 
End ; 
temp^.key:=x; 
temp^.next :=nil; 
new(p2); 
x :=5; 
P2^.key:=x; 
temp:=p2; 
new (temp^.next); 
next 
20 
i 
15 
10 
x 
5 
5 
2 
p2 
nil 
3 
temp 
We create the first node befor we start the repetitive loop 
temp 
10 
20 
temp 
temp 
15 
4 
Each list must end with nil
Procedure Add element to the list : 
To add element to the list we must keep attention to three cases : 
1.The list is empty 
2.Add in the beginning of the list 
3.Add in the middle or at the end of the list 
Guide: to add a node to the list you must have two pointers , one refers to the previous node and the other refers to the following node ,from Place Addition 
9 
8 
3 
P 
5 
{general}
Ex : 
We have a list each node in it takes the following form : 
Name 
Age 
next 
Key =record 
Assuming that the list arranged by (Name) 
Write procedure to add node to the list where does not change the list arrangement 
Type 
Std=record age: integer; name: string; end; 
Ptr = ^node; 
node=record key: std; next: ptr; end; 
Let’s do it ….
Procedure addelem(var p : ptr ; vstd : std ) ; 
Var 
pre,s,temp : ptr ; 
located : Boolean ; 
Begin 
new(temp); 
temp^.key :vstd; 
temp^.next :nil; 
If p=nil then 
p:=temp 
else 
begin 
s :=p; 
pre:=nil; 
located :=false; 
While (s<>nil) and (not located) do 
Begin 
If (s^.key.name < vstd.name) then 
begin 
pre:=s; 
s:=s^.next; 
end 
else 
located:=true; 
end; 
temp^.next:=s; 
if s=p then 
p:=temp; 
else 
pre^.next:=temp; 
end ; 
End; {procedure} 
{Create node } 
{Add in the middle or at the end of the list } 
{List is empty} 
{Find the right place} 
{Add in the beginning of the list} 
{ initialize }
next 
Hussam 
p 
nil 
22 
Salma 
18 
Jad 
25 
name 
Age 
{new(temp); 
temp^.key :vstd; 
temp^.next :nil; 
Ahmed 
20 
Ahmed 
20 
here 
next 
Hussam 
p 
nil 
22 
Salma 
18 
Jad 
25 
Ahmed 
20 
{Add in the beginning of the list }
next 
Hussam 
22 
Salma 
18 
Jad 
25 
p 
Kinan 
20 
here 
next 
Hussam 
22 
Salma 
18 
Jad 
25 
p 
Kinan 
20 
{Add in the middle of the list }
Procedure delete node from the list : 
To delete node from the list we must take into account three cases : 
1.Element to be deleted does not exist 
2.Deletion in the beginning of the list 
3.Deletion in the middle or at the end of the list 
P 
Pre
Procedure deletenode(var p:Ptr; var flag:char; key:integer) 
Var temp,s :ptr; located:=Boolean; 
Begin 
If p=nil then 
flag:=‘3’ 
Else 
Begin 
if p^.key=key then 
begin 
flag:=‘1’; 
temp:=p; 
p:=p^.next; 
dispose(temp); 
end 
else 
begin 
s:=p; 
located:=false; 
While (s^.next<>nil) and (not located) do 
Begin 
if (s^.next^.key<>key) then 
s:=s^.next 
else 
located:=true; 
end; 
If located then 
begin 
flag:=‘1’; 
temp:=s^.next; 
s^.next:=s^.next^.next; 
dispose(temp); 
end 
Else flag:=‘2’; 
end; end; 
End; 
{List is empty} 
{Deletion in the beginning of the list} 
{Find the element you want to delete} 
{Do the deletion} 
{element not found} 
{initialize}
p 
S 
next 
20 
15 
10 
5 
temp 
nil 
next 
20 
10 
5 
p 
nil 
{Deletion in the middle of the list }
Homework: 
ان سًأنح 1 : نذ اٌُ سهسهح )لائحح يشتثطح ي طشف واحذ ( 
ع اُصشها يشتثح تٌض كم ع صُش سجم حٌتىي عهى ) id , 
name ) 
أكتة تش اَيجا قٌىو ت قُم انع اُصش راخ انق حًٍ id انفشد حٌ إنى 
يهف ث اُئ يع يشاعاج حزف انع صُش ان قًُىل يثاششج تعذ قَهه 
إنى ان هًف ثى طثاعح ان هًف وانسهسهح 
ان سًأنح 2 : أكتة الإجشائ اٍخ وانتىاتع انتان حٍ : 
 إجشائ حٍ نهثحث ع أول ع صُش أكثش ي n ي قائ حً ي الأعذاد ان ىًجثح يشتثح تصاعذ اٌ تح ثٍ عٌ ذٍ )- 1 ( ف حال نى 
تٌى انعثىس عهى عذد أكثش ي n 
 إجشائ حٍ نهثحث ع أخش ع صُش أصغش ي m ي قائ حً ي الأعذاد ان ىًجثح ان شًتثح تصاعذ اٌ 
 إجشائ حٍ لإضافح ع صُش ) k ( ف ان كًا ان اًُسة ف انسهسهح 
 إجشائ حٍ تقىو تتثذ مٌ ع صُش ون كٍ m,n ي انسهسهح 
ان ذًخهح 
أستخذو الإجشائ اٍخ انساتقح ف تش اَيج سئ سٍ قٌىو تإ شَاء 
سهسهح ي الأعذاد انصح حٍح ان شًتثح تصاعذ اٌ عهى انشكم 
انتان 2,4,6….192} { تتشت ةٍ ) FIFO ) 
ان سًانح 3 : أكتة تش اَيج لإ شَاء سهسهت الأونى )1P ( عذد 
ع اُصشها ) n ( ذٌخهها ان سًتخذو تتشت ةٍ ) FIFO ( وانثا حٍَ) P2 ) 
عذد ع اُصشها ) m ( ذٌخهها ان سًتخذو تتشت ةٍ ) FILO ( ثى قى 
تحزف انع اُصش انت تقثم انقس حً عهى 3 ف انسهسهح 
الأونى ثى قى تذيج انسهسهت تسهسهح واحذج تثذأ ب p2 
وت تُه ب p1 
Good luck….. 
Kinan 
Group : group link 
Mobile phone- Kinan : 0994385748 
Facebook account : kinan’s account 
2 bytes team

Mais conteúdo relacionado

Mais procurados (15)

Link list
Link listLink list
Link list
 
Linked list
Linked listLinked list
Linked list
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
Variables 2
Variables 2Variables 2
Variables 2
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
Linked list
Linked listLinked list
Linked list
 
LINKED LISTS
LINKED LISTSLINKED LISTS
LINKED LISTS
 
Linked list
Linked list Linked list
Linked list
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
T0
T0T0
T0
 
Theta notation
Theta notationTheta notation
Theta notation
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Section 1-5
Section 1-5Section 1-5
Section 1-5
 

Destaque (17)

Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
E learning y b-learning
E learning y b-learningE learning y b-learning
E learning y b-learning
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Unit i
Unit iUnit i
Unit i
 
Data Structure (Circular Linked List)
Data Structure (Circular Linked List)Data Structure (Circular Linked List)
Data Structure (Circular Linked List)
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Unit iii(dsc++)
Unit iii(dsc++)Unit iii(dsc++)
Unit iii(dsc++)
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
Linked lists
Linked listsLinked lists
Linked lists
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
linked list
linked list linked list
linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list
Linked listLinked list
Linked list
 

Semelhante a 2Bytesprog2 course_2014_c6_single linked list

linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxMeghaKulkarni27
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptxchin463670
 
Double linked list c8
Double linked list c8Double linked list c8
Double linked list c8Omar Al-Sabek
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docxnona800027
 
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfIn an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfezzi552
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointerskinan keshkeh
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Searchecomputernotes
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32ecomputernotes
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questionsGradeup
 

Semelhante a 2Bytesprog2 course_2014_c6_single linked list (20)

linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ll.pptx
Ll.pptxLl.pptx
Ll.pptx
 
Double linked list c8
Double linked list c8Double linked list c8
Double linked list c8
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
What is Linked List in C.docx
What is Linked List in C.docxWhat is Linked List in C.docx
What is Linked List in C.docx
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Cpp lernaufgabe linked_list
Cpp lernaufgabe linked_listCpp lernaufgabe linked_list
Cpp lernaufgabe linked_list
 
Sorting
SortingSorting
Sorting
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdfIn an ancient land, the beautiful princess Eve had many suitors She d.pdf
In an ancient land, the beautiful princess Eve had many suitors She d.pdf
 
Data structure
Data  structureData  structure
Data structure
 
2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers2Bytesprog2 course_2014_c5_pointers
2Bytesprog2 course_2014_c5_pointers
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Computer notes - Binary Search
Computer notes - Binary SearchComputer notes - Binary Search
Computer notes - Binary Search
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
computer notes - Data Structures - 32
computer notes - Data Structures - 32computer notes - Data Structures - 32
computer notes - Data Structures - 32
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
 

Mais de kinan keshkeh

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)kinan keshkeh
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods kinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm kinan keshkeh
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...kinan keshkeh
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graphkinan keshkeh
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_unitskinan keshkeh
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfileskinan keshkeh
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfileskinan keshkeh
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_recordskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_setskinan keshkeh
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templateskinan keshkeh
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphismkinan keshkeh
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritancekinan keshkeh
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces kinan keshkeh
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays kinan keshkeh
 

Mais de kinan keshkeh (20)

10 Little Tricks to Get Your Class’s Attention (and Hold It)
10 Little Tricks to Get Your  Class’s Attention (and Hold It)10 Little Tricks to Get Your  Class’s Attention (and Hold It)
10 Little Tricks to Get Your Class’s Attention (and Hold It)
 
Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods Simpson and lagranje dalambair math methods
Simpson and lagranje dalambair math methods
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm  GeneticAlgorithms_AND_CuttingWoodAlgorithm
GeneticAlgorithms_AND_CuttingWoodAlgorithm
 
Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...Algorithm in discovering and correcting words errors in a dictionary or any w...
Algorithm in discovering and correcting words errors in a dictionary or any w...
 
2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph2Bytesprog2 course_2014_c9_graph
2Bytesprog2 course_2014_c9_graph
 
2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units2Bytesprog2 course_2014_c8_units
2Bytesprog2 course_2014_c8_units
 
2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles2Bytesprog2 course_2014_c4_binaryfiles
2Bytesprog2 course_2014_c4_binaryfiles
 
2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles2Bytesprog2 course_2014_c3_txtfiles
2Bytesprog2 course_2014_c3_txtfiles
 
2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records2Bytesprog2 course_2014_c2_records
2Bytesprog2 course_2014_c2_records
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets2Bytesprog2 course_2014_c1_sets
2Bytesprog2 course_2014_c1_sets
 
2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates2 BytesC++ course_2014_c13_ templates
2 BytesC++ course_2014_c13_ templates
 
2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism2 BytesC++ course_2014_c12_ polymorphism
2 BytesC++ course_2014_c12_ polymorphism
 
2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance2 BytesC++ course_2014_c11_ inheritance
2 BytesC++ course_2014_c11_ inheritance
 
2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces 2 BytesC++ course_2014_c10_ separate compilation and namespaces
2 BytesC++ course_2014_c10_ separate compilation and namespaces
 
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays 2 BytesC++ course_2014_c9_ pointers and dynamic arrays
2 BytesC++ course_2014_c9_ pointers and dynamic arrays
 

Último

What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 

Último (20)

2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 

2Bytesprog2 course_2014_c6_single linked list

  • 1. Prog_2 course- 2014 2 bytes team Kinan keshkeh IT Engineering-Damascus University 3rd year
  • 2. Single linked list Locomotive and trailer
  • 3. Why linked list ? When we deal with arrays sometimes we are exposed to the problem is ((constant Reservation in memory )) That means the size of the array already constant and we can’t change it in program We can use pointer to set up data structure Similar array but it allows us to change their size in the program during execution This data structure is named ((linked list))
  • 4. Linked list are divided into : Single linked list Double linked list Circular linked list In the second year
  • 5. Single linked list : list is elements of record type one of it fields pointer on another record Consists of a list of elements that are arranged where each element is assigned with the following element- with pointer, as in the following example: Definition : p type type type type nil H d u a <type>; char integer 11 10 22 7 Type ptr=^node; node = record ; Key : next : ptr; end ; Var p : ptr;
  • 6. Create list : We can create a single linked list of two ways : From the last node to the first one(FILO) 1 4 multiples Ex : Write procedure to create single linked list include Multiples number (3) Limited within the domain of 1 to 14, where the list is building from the last node to the first one 4 nodes numbers are { 3,6,9,12 } Type ptr=^node Node=record Key : integer ; Next : ptr ; End ;
  • 7. Procedure create1(var p1:ptr); Var temp: ptr; x,i : integer; Begin for i:=1 to 4 do begin end ; End ; p1:=nil; x:=3; new ( temp ); temp^.key :=x; temp^.next := p1 ; p1 := temp; x := x+3; x i p1 Nil next Nil temp 12 3 1 9 p1 3 p1 6 12 6 3 2 9 temp p1 4 temp temp p1
  • 8. Create list : From the first node to the last one (FIFO) : 2 Ex : Write procedure to create single linked list include Multiples number (5) Limited within the domain of 1 to 20, where the list is building from the first node to the last one Procedure create2( var p2 :ptr ); Var temp:ptr; x,i : integer; Begin x :=5; new(p2); p2.key:=x; temp:=p2; For i:=2 to 4 do Begin new (temp^.next); temp:= temp^.next; x:=x+5; temp^.key:=x; end; temp^.next :=nil; End ;
  • 9. Procedure create2( var p2 :ptr ); Var temp:ptr; x,i : integer; Begin For i:=2 to 4 do Begin temp:= temp^.next; x:=x+5; end; End ; temp^.key:=x; temp^.next :=nil; new(p2); x :=5; P2^.key:=x; temp:=p2; new (temp^.next); next 20 i 15 10 x 5 5 2 p2 nil 3 temp We create the first node befor we start the repetitive loop temp 10 20 temp temp 15 4 Each list must end with nil
  • 10. Procedure Add element to the list : To add element to the list we must keep attention to three cases : 1.The list is empty 2.Add in the beginning of the list 3.Add in the middle or at the end of the list Guide: to add a node to the list you must have two pointers , one refers to the previous node and the other refers to the following node ,from Place Addition 9 8 3 P 5 {general}
  • 11. Ex : We have a list each node in it takes the following form : Name Age next Key =record Assuming that the list arranged by (Name) Write procedure to add node to the list where does not change the list arrangement Type Std=record age: integer; name: string; end; Ptr = ^node; node=record key: std; next: ptr; end; Let’s do it ….
  • 12. Procedure addelem(var p : ptr ; vstd : std ) ; Var pre,s,temp : ptr ; located : Boolean ; Begin new(temp); temp^.key :vstd; temp^.next :nil; If p=nil then p:=temp else begin s :=p; pre:=nil; located :=false; While (s<>nil) and (not located) do Begin If (s^.key.name < vstd.name) then begin pre:=s; s:=s^.next; end else located:=true; end; temp^.next:=s; if s=p then p:=temp; else pre^.next:=temp; end ; End; {procedure} {Create node } {Add in the middle or at the end of the list } {List is empty} {Find the right place} {Add in the beginning of the list} { initialize }
  • 13. next Hussam p nil 22 Salma 18 Jad 25 name Age {new(temp); temp^.key :vstd; temp^.next :nil; Ahmed 20 Ahmed 20 here next Hussam p nil 22 Salma 18 Jad 25 Ahmed 20 {Add in the beginning of the list }
  • 14. next Hussam 22 Salma 18 Jad 25 p Kinan 20 here next Hussam 22 Salma 18 Jad 25 p Kinan 20 {Add in the middle of the list }
  • 15. Procedure delete node from the list : To delete node from the list we must take into account three cases : 1.Element to be deleted does not exist 2.Deletion in the beginning of the list 3.Deletion in the middle or at the end of the list P Pre
  • 16. Procedure deletenode(var p:Ptr; var flag:char; key:integer) Var temp,s :ptr; located:=Boolean; Begin If p=nil then flag:=‘3’ Else Begin if p^.key=key then begin flag:=‘1’; temp:=p; p:=p^.next; dispose(temp); end else begin s:=p; located:=false; While (s^.next<>nil) and (not located) do Begin if (s^.next^.key<>key) then s:=s^.next else located:=true; end; If located then begin flag:=‘1’; temp:=s^.next; s^.next:=s^.next^.next; dispose(temp); end Else flag:=‘2’; end; end; End; {List is empty} {Deletion in the beginning of the list} {Find the element you want to delete} {Do the deletion} {element not found} {initialize}
  • 17. p S next 20 15 10 5 temp nil next 20 10 5 p nil {Deletion in the middle of the list }
  • 18. Homework: ان سًأنح 1 : نذ اٌُ سهسهح )لائحح يشتثطح ي طشف واحذ ( ع اُصشها يشتثح تٌض كم ع صُش سجم حٌتىي عهى ) id , name ) أكتة تش اَيجا قٌىو ت قُم انع اُصش راخ انق حًٍ id انفشد حٌ إنى يهف ث اُئ يع يشاعاج حزف انع صُش ان قًُىل يثاششج تعذ قَهه إنى ان هًف ثى طثاعح ان هًف وانسهسهح ان سًأنح 2 : أكتة الإجشائ اٍخ وانتىاتع انتان حٍ :  إجشائ حٍ نهثحث ع أول ع صُش أكثش ي n ي قائ حً ي الأعذاد ان ىًجثح يشتثح تصاعذ اٌ تح ثٍ عٌ ذٍ )- 1 ( ف حال نى تٌى انعثىس عهى عذد أكثش ي n  إجشائ حٍ نهثحث ع أخش ع صُش أصغش ي m ي قائ حً ي الأعذاد ان ىًجثح ان شًتثح تصاعذ اٌ  إجشائ حٍ لإضافح ع صُش ) k ( ف ان كًا ان اًُسة ف انسهسهح  إجشائ حٍ تقىو تتثذ مٌ ع صُش ون كٍ m,n ي انسهسهح ان ذًخهح أستخذو الإجشائ اٍخ انساتقح ف تش اَيج سئ سٍ قٌىو تإ شَاء سهسهح ي الأعذاد انصح حٍح ان شًتثح تصاعذ اٌ عهى انشكم انتان 2,4,6….192} { تتشت ةٍ ) FIFO ) ان سًانح 3 : أكتة تش اَيج لإ شَاء سهسهت الأونى )1P ( عذد ع اُصشها ) n ( ذٌخهها ان سًتخذو تتشت ةٍ ) FIFO ( وانثا حٍَ) P2 ) عذد ع اُصشها ) m ( ذٌخهها ان سًتخذو تتشت ةٍ ) FILO ( ثى قى تحزف انع اُصش انت تقثم انقس حً عهى 3 ف انسهسهح الأونى ثى قى تذيج انسهسهت تسهسهح واحذج تثذأ ب p2 وت تُه ب p1 Good luck….. Kinan 
  • 19. Group : group link Mobile phone- Kinan : 0994385748 Facebook account : kinan’s account 2 bytes team