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

    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
  • Satisfactory Essays

    Unit 8 Assignment

    • 380 Words
    • 2 Pages

    e. ____________________ is the use of an algorithm to scramble data into a format that can be read only by reversing the algorithm.…

    • 380 Words
    • 2 Pages
    Satisfactory 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
  • Good Essays

    Comp 220

    • 1463 Words
    • 6 Pages

    Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.…

    • 1463 Words
    • 6 Pages
    Good 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

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory 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
  • 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
  • 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