Preview

Linked List

Powerful Essays
Open Document
Open Document
3270 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Linked List
Linked List

July 21, 2009

Programming and Data Structure

1

Introduction
• A linked list is a data structure which can change during execution.
– Successive elements are connected by pointers. – Last element points to NULL. – It can grow or shrink in size during execution of a program. – It can be made just as long as required. – It does not waste memory space. A
July 21, 2009

head

B
Programming and Data Structure

C
2

• Keeping track of a linked list:
– Must know the pointer to the first element of the list (called start, head, etc.).

• Linked lists provide flexibility in allowing the items to be rearranged efficiently.
– Insert an element. – Delete an element.

July 21, 2009

Programming and Data Structure

3

Illustration: Insertion
A B C

X

Item to be inserted

A

B

C

X
July 21, 2009 Programming and Data Structure 4

Illustration: Deletion
Item to be deleted

A

B

C

A

B

C

July 21, 2009

Programming and Data Structure

5

In essence ...
• For insertion:
– A record is created holding the new item. – The next pointer of the new record is set to link it to the item which is to follow it in the list. – The next pointer of the item which is to precede it must be modified to point to the new item.

• For deletion:
– The next pointer of the item immediately preceding the one to be deleted is altered, and made to point to the item following the deleted item.
July 21, 2009 Programming and Data Structure 6

Array versus Linked Lists
• Arrays are suitable for:
– Inserting/deleting an element at the end. – Randomly accessing any element. – Searching the list for a particular value.

• Linked lists are suitable for:
– – – – Inserting an element. Deleting an element. Applications where sequential access is required. In situations where the number of elements cannot be predicted beforehand.
Programming and Data Structure 7

July 21, 2009

Types of Lists
• Depending on

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    it the functions listed below for Exercise 2. In each case, the appropriate error message should be generated if an invalid condition occurs. For example, an error message should be generated when trying to insert an item in a given location in the list and the location is out of range, a. ArrayList(inl size): create a constructor that sets the size of the array list to the value passed in size (note that the class variable SIZE cannot be final anymore), b. int length(): create this function to determine the number of items in the list (accessor function), c. int gelSize(): create this function to determine the size of the list (accessor function), d. void clear(): create this function to remove all of the items from the list. After this operation, the length of the list is zero, e. void replace(int location, int item): create this function to replace the item in the list at the position specified by location. The item should be replaced with item. f. void insert(int location, int item): create this function to add an item to the list at the position specified by location, g. void remove(int item): create this function to delete an item from the list. All ...…

    • 714 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    This week learning assignment is based on Unit 8 Chapter 6 reading of the textbook about the elements of a computing system that focus on the selections relevant for supporting programs with symbols.…

    • 288 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    Searching and Sorting Streams and Files Graphics GUI Components and Events Mouse, Keyboard, Sounds, and Images Big-O Analysis of Algorithms The Java Collections Framework Lists and Iterators Stacks and Queues Recursion Revisited Binary Trees Lookup Tables and Hashing Heaps and Priority Queues Design Patterns…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Satisfactory Essays

    CS305 Final Exam Questions

    • 1044 Words
    • 6 Pages

    c. It increments the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.…

    • 1044 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    Info1105

    • 951 Words
    • 4 Pages

    Now if we traverse the list from head to tail, we always get a sorted list.…

    • 951 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    cis121 chapter 2 and 3

    • 993 Words
    • 6 Pages

    A ____ read is an added statement that gets the first input value in a program.…

    • 993 Words
    • 6 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Data Structure

    • 328 Words
    • 2 Pages

    How do you randomly select an item in a list? How do you randomly select an item in an array?…

    • 328 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    [Type the abstract of the document here. The abstract is typically a short summary of the contents of the document. Type the abstract of the document here. The abstract is typically a short summary of the contents of the document.]…

    • 5806 Words
    • 24 Pages
    Powerful Essays
  • Satisfactory Essays

    Data Structure

    • 785 Words
    • 4 Pages

    2. Write a test program that keeps the list of the following fruit items called fruitQ in the queue in the following order: Apple, Orange, Grapes, Cherry. Perform the following operations…

    • 785 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Doubly Linklist

    • 555 Words
    • 3 Pages

    #include<stdio.h> #include<conio.h> #include<alloc.h> typedef struct dll { int data; struct dll *next; struct dll *prev; }node; //struct dll *head= NULL; node *getnode() { node *temp; temp=(node *)malloc(sizeof(node)); temp->next= NULL; temp->prev=NULL; return temp; } node *creation() { node *temp,*new1,*head; int f=1; char c; do { new1=getnode(); printf("\n\nEnter the data.\n\n"); scanf("%d",&new1->data); if(f==1) { head=new1; temp=head; f=0; } else { temp->next=new1; new1->prev=temp; temp=new1; } printf("\n\nDo you want to continue with creation.\n\n"); c=getche(); }while(c=='y'||c=='Y'); return head; } void display(node *head) { node *temp; temp=head; printf("\n\nThe list is...\n\n"); while(temp!=NULL) { printf("%d\n",temp->data); temp=temp->next; } } node *insertion(node *head) { node *new1,*temp; int c,value; char ch; do { new1=getnode(); printf("\n\nEnter the data to be insered.\n\n"); scanf("%d",&new1->data); printf("\n\nEnter your place of insertion.\n\n"); printf("\n1.Head.\n2.Intermediate.\n3.Tail.\n"); scanf("%d",&c); switch(c) { case 1: temp=head; new1->next=temp; temp->prev=new1; head=new1; break; case 2: temp=head; printf("\n\nEnter the value after which the insertion has to take place.\n\n"); scanf("%d",&value); while(temp->data!=value) { temp=temp->next; } temp->next->prev=new1; new1->next=temp->next; temp->next=new1; new1->prev=temp; break; case 3: temp=head; while(temp->next!=NULL) { temp=temp->next; } temp->next= new1; new1->next=…

    • 555 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Bullshit 101

    • 822 Words
    • 3 Pages

    CE 323 Assignment 3 Design Pattern Mustafa Mohammad Ghazanfar 2011329 12/16/2013 Strategy Pattern: Strategy pattern can be used in cases where behaviours of certain elements can be separated from other parts as independent processes. For example designing a strategy pattern for a car would result in multiple functions like brakes, boot, windows etc. All will have separate functions yet come together to complete the car. This pattern works by encapsulating all the functions as separately as possible and all the while keeping the client encapsulated from majority of the algorithm.…

    • 822 Words
    • 3 Pages
    Good Essays
  • Good Essays

    Linux

    • 1166 Words
    • 5 Pages

    TERM PAPER Of FOUNDATION OF COMPUTING Topic: - TELEPHONE DIRECTORY Submitted To: - Submitted By:- MOHIT JAIN MR.VIJAY KUMAR SOURCE CODE //TETEPHONR…

    • 1166 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    Chefe

    • 690 Words
    • 3 Pages

    During this course we will follow the same data storing structure as used by the…

    • 690 Words
    • 3 Pages
    Satisfactory Essays