SlideShare a Scribd company logo
1 of 4
C/C++
Create a inked list of up to 20 peripherals.
Hold data about peripheral in a structure.
Provide for adding new peripherals, finding and removing them.
Minimize code by leveraging code reuse.
struct peripheral
{
struct peripheral *next;
char *name;
char *description;
}
#define new(a) malloc(sizeof(struct a));
#define MAX_P 20;
int total = 0;
main
{
struct peripherial *root;
root = malloc(sizeof(struct peripheral));
(*root).next, or
root->next = new(peripheral);
root->name = “keyboard”;
root->next-> = “mouse”;
// find the mouse peripheral
struct peripherial *mouse = findByNameLast(root,”mouse”)->next; // ->next =’s findByName;
}
struct peripheral* findByNameLast(peripheral* start, char* input)
{
if(start->next != null)
{
if(strcmp(start->name,input) == 0)
{
return start;
}
else if(start->next != null)
{
findByNameLast(start->next,input);
}
else if(start->next-next != null)
{
findByNameLast(start->next,input);
}
else
{
return NULL;
}
}
else
{
return NULL;
}
}
struct peripheral* insertAfter(struct peripheral* start, char* input)
{
if(total < MAX_P)
{
struct peripheral* new = new(peripheral);
new->name = strcpy(input);
new->next = start->next;
start->next = new;
total++;
return start->next;
}
else
{
return NULL;
}
}
struct peripheral* removeByName(peripheral* start, char* input)
{
if(removeable == root)
{
root = root->next;
return root;
}
struct peripheral* last = findByNameLast(start,input);
if(last != NULL)
{
last->next = last-next->next;
return last->next;
}
return NULL;
}

More Related Content

What's hot

Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断nishio
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterakaptur
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...akaptur
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocationUtsav276
 
as400 built in function- %REPLACE
as400 built in function- %REPLACEas400 built in function- %REPLACE
as400 built in function- %REPLACEaminem_mp
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTEr. Ganesh Ram Suwal
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment pcnmtutorials
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked ListSayantan Sur
 
Diving into byte code optimization in python
Diving into byte code optimization in python Diving into byte code optimization in python
Diving into byte code optimization in python Chetan Giridhar
 
Python for Scientists
Python for ScientistsPython for Scientists
Python for ScientistsAndreas Dewes
 
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)indiangarg
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs董 伟明
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationNaveen Gupta
 

What's hot (20)

Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
Vcs23
Vcs23Vcs23
Vcs23
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
言語の設計判断
言語の設計判断言語の設計判断
言語の設計判断
 
Bytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreterBytes in the Machine: Inside the CPython interpreter
Bytes in the Machine: Inside the CPython interpreter
 
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!..."A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
"A 1,500 line (!!) switch statement powers your Python!" - Allison Kaptur, !!...
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocation
 
as400 built in function- %REPLACE
as400 built in function- %REPLACEas400 built in function- %REPLACE
as400 built in function- %REPLACE
 
Duralexsedregex
DuralexsedregexDuralexsedregex
Duralexsedregex
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
 
Stack using Linked List
Stack using Linked ListStack using Linked List
Stack using Linked List
 
Diving into byte code optimization in python
Diving into byte code optimization in python Diving into byte code optimization in python
Diving into byte code optimization in python
 
Python for Scientists
Python for ScientistsPython for Scientists
Python for Scientists
 
Software Exploits
Software ExploitsSoftware Exploits
Software Exploits
 
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)
Some Commonly asked Function/Objects Vs. header files (CBSE 12th Exam)
 
我在豆瓣使用Emacs
我在豆瓣使用Emacs我在豆瓣使用Emacs
我在豆瓣使用Emacs
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 

Viewers also liked

Algebra tema1teoria(10 11)
Algebra tema1teoria(10 11)Algebra tema1teoria(10 11)
Algebra tema1teoria(10 11)Manu Medi
 
MotivationLetterEszterBotka2015
MotivationLetterEszterBotka2015MotivationLetterEszterBotka2015
MotivationLetterEszterBotka2015Eszter Botka
 
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)ExpoSchoolaanZet
 
Clara Luz Roldán Inscribe Candidatura en Registraduria
Clara Luz Roldán Inscribe Candidatura en RegistraduriaClara Luz Roldán Inscribe Candidatura en Registraduria
Clara Luz Roldán Inscribe Candidatura en RegistraduriaClara Luz Roldán
 
Church Archives 101
Church Archives 101Church Archives 101
Church Archives 101StanUpchurch
 
Eleink asztalánál 7
Eleink asztalánál 7Eleink asztalánál 7
Eleink asztalánál 7Agnes Tip
 
Animal powerpoint
Animal powerpointAnimal powerpoint
Animal powerpointjrose101
 
Presentacion de trabajo gbi
Presentacion de trabajo gbiPresentacion de trabajo gbi
Presentacion de trabajo gbiJuli CR
 
六合彩|香港六合彩
六合彩|香港六合彩六合彩|香港六合彩
六合彩|香港六合彩mftldtw
 
Www Powerpoint
Www PowerpointWww Powerpoint
Www Powerpointkrit11145
 
Ec4333 Lecture3 2007 Slide Share
Ec4333 Lecture3 2007 Slide ShareEc4333 Lecture3 2007 Slide Share
Ec4333 Lecture3 2007 Slide ShareStephen Kinsella
 
Multicultural Final Project
Multicultural Final ProjectMulticultural Final Project
Multicultural Final Projectguest731db42f
 
08 07( July) 10 Laporan C B I
08 07( July) 10 Laporan  C B I08 07( July) 10 Laporan  C B I
08 07( July) 10 Laporan C B IKay Karim
 

Viewers also liked (19)

Algebra tema1teoria(10 11)
Algebra tema1teoria(10 11)Algebra tema1teoria(10 11)
Algebra tema1teoria(10 11)
 
MotivationLetterEszterBotka2015
MotivationLetterEszterBotka2015MotivationLetterEszterBotka2015
MotivationLetterEszterBotka2015
 
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)
Jeroen van Grunsven, sturen naar een beter (examen)resultaat (Rotterdam)
 
Clara Luz Roldán Inscribe Candidatura en Registraduria
Clara Luz Roldán Inscribe Candidatura en RegistraduriaClara Luz Roldán Inscribe Candidatura en Registraduria
Clara Luz Roldán Inscribe Candidatura en Registraduria
 
Naqel case study
Naqel case studyNaqel case study
Naqel case study
 
Church Archives 101
Church Archives 101Church Archives 101
Church Archives 101
 
Eleink asztalánál 7
Eleink asztalánál 7Eleink asztalánál 7
Eleink asztalánál 7
 
Win8 in the enterprise
Win8 in the enterpriseWin8 in the enterprise
Win8 in the enterprise
 
Animal powerpoint
Animal powerpointAnimal powerpoint
Animal powerpoint
 
Presentacion de trabajo gbi
Presentacion de trabajo gbiPresentacion de trabajo gbi
Presentacion de trabajo gbi
 
六合彩|香港六合彩
六合彩|香港六合彩六合彩|香港六合彩
六合彩|香港六合彩
 
Www Powerpoint
Www PowerpointWww Powerpoint
Www Powerpoint
 
Percorso Artistico 5
Percorso Artistico 5Percorso Artistico 5
Percorso Artistico 5
 
Psicopedago gia
Psicopedago giaPsicopedago gia
Psicopedago gia
 
Ec4333 Lecture3 2007 Slide Share
Ec4333 Lecture3 2007 Slide ShareEc4333 Lecture3 2007 Slide Share
Ec4333 Lecture3 2007 Slide Share
 
XEL_Q305
XEL_Q305XEL_Q305
XEL_Q305
 
Chapitre 7
Chapitre 7Chapitre 7
Chapitre 7
 
Multicultural Final Project
Multicultural Final ProjectMulticultural Final Project
Multicultural Final Project
 
08 07( July) 10 Laporan C B I
08 07( July) 10 Laporan  C B I08 07( July) 10 Laporan  C B I
08 07( July) 10 Laporan C B I
 

Similar to CLinkedList

VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and CEleanor McHugh
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfSANDEEPARIHANT
 
Implementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docxImplementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docxRyanEAcTuckern
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docxAbdulrahman890100
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfwasemanivytreenrco51
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdfanujmkt
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfarihantstoneart
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfVishwasChoclaty1
 

Similar to CLinkedList (20)

DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
C program
C programC program
C program
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 
Implementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docxImplementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docx
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Describe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdfDescribe a data structure that supports both removeMin() and rem.pdf
Describe a data structure that supports both removeMin() and rem.pdf
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdf
 

More from Thomas Knudstrup (9)

NinjaSynch
NinjaSynchNinjaSynch
NinjaSynch
 
GreyCount
GreyCountGreyCount
GreyCount
 
Generics
GenericsGenerics
Generics
 
distill
distilldistill
distill
 
assembly
assemblyassembly
assembly
 
Fibonnaci
FibonnaciFibonnaci
Fibonnaci
 
HappyFeat
HappyFeatHappyFeat
HappyFeat
 
Sorter
SorterSorter
Sorter
 
Sorter
SorterSorter
Sorter
 

CLinkedList

  • 1. C/C++ Create a inked list of up to 20 peripherals. Hold data about peripheral in a structure. Provide for adding new peripherals, finding and removing them. Minimize code by leveraging code reuse. struct peripheral { struct peripheral *next; char *name; char *description; } #define new(a) malloc(sizeof(struct a)); #define MAX_P 20; int total = 0; main { struct peripherial *root; root = malloc(sizeof(struct peripheral)); (*root).next, or root->next = new(peripheral); root->name = “keyboard”; root->next-> = “mouse”; // find the mouse peripheral struct peripherial *mouse = findByNameLast(root,”mouse”)->next; // ->next =’s findByName;
  • 2. } struct peripheral* findByNameLast(peripheral* start, char* input) { if(start->next != null) { if(strcmp(start->name,input) == 0) { return start; } else if(start->next != null) { findByNameLast(start->next,input); } else if(start->next-next != null) { findByNameLast(start->next,input); } else { return NULL; } } else {
  • 3. return NULL; } } struct peripheral* insertAfter(struct peripheral* start, char* input) { if(total < MAX_P) { struct peripheral* new = new(peripheral); new->name = strcpy(input); new->next = start->next; start->next = new; total++; return start->next; } else { return NULL; } } struct peripheral* removeByName(peripheral* start, char* input) { if(removeable == root) {
  • 4. root = root->next; return root; } struct peripheral* last = findByNameLast(start,input); if(last != NULL) { last->next = last-next->next; return last->next; } return NULL; }