Preview

Linked list

Good Essays
Open Document
Open Document
1308 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Linked list
• Linked List Implementation/Coding Issues in C
• We can define structures with pointer fields that refer to the structure type containing them






struct list { int data; struct list *next;
}

• data

next

• The pointer variable next is called a link. Each structure is linked to a succeeding structure by way of the field next. The pointer variable next contains an address of either the location in memory of the successor struct list element or the special value NULL.

• Example









struct list a, b, c;
a.data = 1;
b.data = 2;
c.data = 3;
a.next = b.next = c.next = NULL;

• a
• 1

• NULL

• data • next

• b
• 2

• NULL

• data • next

• c
• 3
NULL
• data • next

• Example continues







a.next
b.next
a.next
a.next
b.next

• a
• 1

= &b;
= &c;
-> data has value 2
-> next -> data has value 3
-> next -> data error !!

• b
• 2

• c
• 3

• Dynamic Memory Allocation

• Creating and maintaining dynamic data structures requires dynamic memory allocation – the ability for a program to obtain more memory space at execution time to hold new values, and to release space no longer needed.
• In C, functions malloc and free, and operator sizeof are essential to dynamic memory allocation.

• Dynamic Memory Operators sizeof and malloc
• Unary operator sizeof is used to determine the size in bytes of any data type. • sizeof(double) sizeof(int)
• Function malloc takes as an argument the number of bytes to be allocated and return a pointer of type void * to the allocated memory. (A void * pointer may be assigned to a variable of any pointer type. ) It is normally used with the sizeof operator.

• Dynamic Memory Operators in C Example









struct node{ int data; struct node *next;
};
struct node *ptr; ptr = (struct node *) /*type casting */ malloc(sizeof(struct node));

• ptr

• ?
• ?

• The Free Operator in C

You May Also Find These Documents Helpful

  • Satisfactory Essays

    NT1210 Lab 1

    • 319 Words
    • 4 Pages

    2. A single byte only contains 8bits of data whereas multiple bytes joined together contain more bits which mean more data.…

    • 319 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 1 Quiz

    • 1980 Words
    • 8 Pages

    6 . For an unconditional approach to a particular part of a complex PL/SQL block, which of the following control structures can be used?…

    • 1980 Words
    • 8 Pages
    Good Essays
  • Satisfactory Essays

    SD1230 Lab 1

    • 239 Words
    • 2 Pages

    1. What is the highest number that can be stored in a byte? – 8 bytes as 11111111 or 255 in decimal.…

    • 239 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1330 Unit 3 Assignment 1

    • 2019 Words
    • 9 Pages

    • Your computer performs a bitwise logical AND operation between the address and…

    • 2019 Words
    • 9 Pages
    Powerful Essays
  • Good Essays

    Nt1310 Unit 3 Quiz

    • 6337 Words
    • 26 Pages

    /*question number 3*/ Code: void *ptr; myStruct myArray[10]; ptr = myArray; Which of the following is the correct…

    • 6337 Words
    • 26 Pages
    Good Essays
  • Good Essays

    | |Unit measurement: The data type should be consistent. For instance, if data is being collected on red blocks, all data should be based directly on red blocks alone. |…

    • 622 Words
    • 3 Pages
    Good Essays
  • Powerful Essays

    Nt1330 Unit 1 Research Paper

    • 4285 Words
    • 18 Pages

    Each character requires one byte as it is usually stored as an ASCII character. Notice that a digit such as 8 could be held as either a character, an integer or even a real. If any calculations are going to take place on the value then it should be held as either an integer or a real. If the calculation will never result in it being extremely large or gaining decimal places then an integer should be used.…

    • 4285 Words
    • 18 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
  • Powerful Essays

    Unit 18 - Database P1, M1

    • 995 Words
    • 4 Pages

    Data type is the type of content and it decides the content can be input and the file size.…

    • 995 Words
    • 4 Pages
    Powerful Essays
  • Good Essays

    Guide to Unix Chapter 2

    • 999 Words
    • 4 Pages

    9. In UNIX and Linux systems, what source of extra memory space is used when…

    • 999 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    Listo System

    • 279 Words
    • 1 Page

    Listo Systems' VISION statement is: "To be recognized as a leader in supplying quality graphic design products and services to our customers and to be respected by our clients and staff.”…

    • 279 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged to explore the design space creatively and implement an allocator that is correct, efficient and fast.…

    • 2325 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    -The numbers after the User’s Group is the File Size, which is measured in bytes or blocks…

    • 1336 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    Data Structure

    • 328 Words
    • 2 Pages

    You would use a list as the data structure if the program would add items to it while it’s running because lists and dynamic where arrays are fixed.…

    • 328 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Data Dictionary

    • 473 Words
    • 2 Pages

    Character (Char), numeric (N) including number of decimals, integer (Smallint, Int), memo, binary, varchar, etc.…

    • 473 Words
    • 2 Pages
    Good Essays

Related Topics