Darshan Institute of Engineering & Technology for Diploma studies Unit 4

Size: px
Start display at page:

Download "Darshan Institute of Engineering & Technology for Diploma studies Unit 4"

Transcription

1 Pointer A pointer is a variable that contains address or location of another variable. Pointer is a derived data type in C. Pointers contain memory address as their values, so they can also be used to access and manipulate data stored in memory. void main() { int a=0, *p; p = &a; // Assign memory address of a to pointer variable p printf( %d %d %d, a, *p, p); } Output: p is integer pointer variable & is address of or referencing operator which returns memory address of variable * is indirection or dereferencing operator which returns value stored at that memory address & operator is the inverse of * operator ( x = a is same as x = *(&a)) Variable Value Address 0 a P 5048 Declaration of pointer, Syntax: data_type *pt_name; Example: int *p, float *q, char *c; ) The asterisk (*) tells that the variable pt_name is a pointer variable 2) pt_name needs a memory location to store address of another variable 3) pt_name points to a variable of type data_type Initialization of the pointer, Structure int a=5, x, *p; // Declares pointer variable p and regular variable a and x p = &a // Initializes p with address of a x = *p; // p contains address of a and *p gives value stored at that address. Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is a user defined data type. Structure helps to organize complex data in a more meaningful way. Dept: CE DS ( ) Vishal Makwana

2 Syntax of Structure: struct structure_name { data_type member; data_type member2; }; struct is a keyword. structure_name is a tag name of a structure. member, member2 are members of structure. Below Program reads and prints employee information: #include <stdio.h> struct employee { int emp_no; char name[20]; int age; }; void main() { struct employee e; printf( Enter employee details\n ); scanf( %d %s %d, &e.emp_no, e.name, &e.age); printf( Employee data is::\n ); printf( %d \n %s\n %d\n, e.emp_no, e.name, e.age); printf( It occupies %d bytes in memory \n, sizeof (struct employee)); } There are two ways to create variables of structure type as discussed below: ) The structure is declared as below: struct employee { int emp_no; char name[20]; int age; }; After making above declaration variable of employee type are created are follows: struct employee e,e2,e3; In above declaration of structure variables e, e & e3, each variable occupies separate memory. Total memory occupy by each variable is 24 bytes as for each data member respectively. 2 Dept: CE DS ( ) Vishal Makwana

3 2) The structure prototype and variables are defined together as follow: struct employee { int emp_no; char name[20]; int age; }e,e2,e3; Initialization of structure For initialization consider structure of employee. struct employee e = {0, xyz, 8}; OR e.emp_no = 0; strcpy (e.name, xyz ); e.age = 8; Structure using Pointers Structures and pointers are used together to design complex data structure used in larger and complex application using pointer of any type as member of structure, pointer to point to structure variable or array of structure, to create structure dynamically at run time etc. Example: Struct point { Int x; Int y; }; struct point *p; struct point p= { 6,8}; p = &p; Now, p points to p and can be used to access x and y coordinates of p. When pointer is used to access structure members we have to use arrow ( -> ) operator, following syntax is used: Structure_pointer -> member_name Similarlly we can use, Scanf ( %d %d, &p->x, &p->y); Printf ( %d\n, p->x); It is also possible that once pointer to structure is declared, structure can be created dynamically as follows: p = (struct point *) malloc (sizeof (stuct point)); Now p points to a structure of type point. 3 Dept: CE DS ( ) Vishal Makwana

4 Dynamic Memory Allocation Using array, we can represent a linear data structure as a sequential allocation (static implementation) method of storage. But this method of allocation is suitable for certain application only. There are so many application where sequential allocation method is not unacceptable such as, ) Unpredictable storage requirement 2) Extensive manipulation of storage data Example: In a program operations such as insertion and deletion are performed frequently on the data. So Linked list (Dynamic memory allocation) method of storage is efficient for computer storage. The dynamic allocation does not allocate the memory at compile time but allocates memory at run time. Hence, there is no wastage of memory. The dynamic allocation increases the execution time of the program because of run time allocation, but it gives total control of memory in hands of programmer. C provides memory management function in library using <malloc.h> header file. The function which is widely used to allocate memory at run time is malloc. Void *malloc(int); Where int argument is number of bytes to be allocated. It returns an address of starting of the block of memory which is allocated. ptr = (target_type *)malloc (no_of_bytes); Above statement returns void pointer to block of memory of size no_of_bytes which must be casted to target data type which is the type of pointer. Then the pointer ptr can be used to access memory block allocated by malloc function. Consider following examples, ) int *p; p = (int *) malloc (sizeof (int) ) ; The above statement allocates memory for one integer. To store the value, we can write *p = 0; 2) float *f; f = (float *) malloc (sizeof (float)); This creates a floating point variable pointed by pointer variable f dynamically. 3) char *str; str = (char *) malloc (0 * sizeof(char)); This creates a string of maximum 0 character pointed by str. 4) Int *p; P = (int *) malloc (5 * sizeof(char)); This creates an array of 5 integers pointed by p. Once an array is created using above statement either subscripted variable or pointer notation can be used to access the individual elements of the array. 4 Dept: CE DS ( ) Vishal Makwana

5 Linked List Presentation A simple way to represent a linear list is to expand each node to contain a link or pointer to the next node. This representation is called a one way chain or singly Linked List. It can be displayed as below: NULL (Single Linked Linear List) The variable contain the address of first node of the list. A linked list is a collection of nodes and each node has two pair: ) Information (INFO) - It contains the actual element of the list. 2) Address or pointer to next node (LINK) - It contain the address of the next node in the list INFO Infomation LINK Address (Node) In a linear list each node contains a link or pointer to the next node. The pointer contains the address of location where next information is stored. LINK of the last node contain a special value known as a NULL, which indicate end of the list. The list with no node is called empty list. The empty list has = NULL. For any operation, first step is to check whether list is empty or not. If list is empty and if we try to delete a node List underflow error occurs. Linked List Example A 200 B 2002 C 202 D Null (2000) Types of Linked List ) Singly Linked List 2) Singly Circular Linked List 3) Doubly Linked List 4) Doubly Circular Linked List 5) Ordered Linked List 5 Dept: CE DS ( ) Vishal Makwana

6 Basic Operation on Singly Linked Linear List ) To create a linked list 2) Traversing a linked list 3) Insert new node at beginning of linked list 4) Insert new node at the end of linked list 5) Insert a node at any location or in between the list 6) Inserting a node into an ordered linear list 7) Delete a first node(at beginning ) of linked list 8) Delete a last node(at end) of linked list 9) Delete a node on basis of node number 0) Searching element in linked list ) Count the number of nodes in linked list To perform above operation following fundamental things are to be considered: Linked list has a pointer variable which stores address of the first node of the list. Likewise, we have a pointer variable AVAIL which stores the address of the first free space of the free pool (Which is linked list of all the free memory cells). This free pool is called availability list. Whenever a node is to be inserted in a list, the memory address pointed by AVAIL pointer will be taken from the availability list and used to store the information. After the insertion, the next available free space s address will be stored in AVAIL pointer. When we delete a particular node from an existing list, the space occupied by it must be given back to the free pool. So that the memory can be reused by some other program. The advantage of this scheme is memory management. Avail New Avail Null (Before) [Availabiitility List] (After) [To free a Node Form avail stack] 6 Dept: CE DS ( ) Vishal Makwana

7 Linked List Creation Algorithm: We consider some variable for writing a algorithm New_Node -> It is temporary variable of node type. Avail -> It is a top pointer of availability of stack of nodes. First -> It is the pointer which will points to front (first) node having INFO & LINK portion X -> It is the variable which will store the value/item at information part ALGORITHM: Create a Linked List Step : [Initially list is empty or check whether any node exist or not] If(First=null) Write( Linked list is empty ); First = NULL; Step 2: [To create new node] [Remove free node from availability list] If(First = NULL) New_Node <- Avail; Avail <- LINK(Avail); Step 3: [Assign a value to information part of node] INFO (New_Node) <- X Step 4: [Assign null to the address part for node to indicate end of list] LINK(New_Node) <- NULL Step 5: [Assign address of first node to first variable] First <- New_Node Step 6: [Return the created node] Return(First) Inserting a node at the beginning of the list: New_Node to be inserted at the beginning of the list Allocates memory for the new node and initialize its data part to Add the new node as the first node of the list. Now the LINK part of the new node contains address of. 7 Dept: CE DS ( ) Vishal Makwana

8 Now is made to point to the first node of the list. ALGORITHM: Insert (x, First) Step : [Check for availability list underflow] if(avail = NULL) Write( Availability stack underflow ) Step 2: [Check whether any nodes exist or not in a list] (A)[If there is not any node in the list remove freed node from availability list] () if(first = NULL) New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to node] INFO(New_Node) <- x (3)[Set link of node to null] LINK(New_Node) <- NULL (B)[If there is any node available in list and insert a new node] ()[Assign data to node] New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to node] INFO(New_Node) <- x (3)[Set link of node] LINK(New_Node) <- First Step 3: [Assign the address of temporary pointer to first pointer] First <- New_Node Step 4: [finished] Inserting a node at the end of the list: We take a which will initially point to , 8 Dept: CE DS ( ) Vishal Makwana

9 7 5 3 Move so that it points to the last node of the list Add the new node after the node pointed by. This is done by storing the address of the new node in the LINK part of. Inserting an element at the end of the Linked List ALGORITHM: InsEnd (x, First) Step : [Check for availability list underflow] If(Avail = NULL) Write( Availability stack is underflow ) Step 2: [Create node and set the data and link portion of node] ()[Remove free node from availability stack] New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to information part of node] INFO(New_Node) <- x (3)[Set the link portion to null because it is last node at end] LINK(New_Node) <- NULL Step 3: [If there is no node in list] If(First ==NULL) First <- New_Node Step 4: [If there is any node in the list and put new node at the end of list] ()[Assign address of first node to ] <- First (2)[Traverse the list till last node is reached] Repeat while( LINK() <> NULL) <- LINK() (3)[Set link of last node to new node] LINK() <- New_Node Step 5: [Finished] 9 Dept: CE DS ( ) Vishal Makwana

10 Inserting a node after given node in the list: Take two pointer variable and PRE and initialize them with so that, and PRE point to the first node of the list ,,PRE Move and PRE until the data part of the PRE = Value of the node after which insertion has to be done. PRE will always point to the node just before PRE Add new node in between the nodes pointed by PRE and New_Node Inserting a node after a given node in the linked list ALGORITHM: InAfterLoc (x, First) Step : [Check for availability list underflow] If(Avail = NULL) Write( Availability stack is underflow ) Step 2: [Create node and set the data and link portion of node] ()[Remove free node from availability stack] New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to information part of node] INFO(New_Node) <- x 0 Dept: CE DS ( ) Vishal Makwana

11 Step 3: [Read location] Read N Step 4: [Set two pointer and PRE to First] = First PRE = Step 5: [Reach to specific location] Repeat while (INFO(PRE) <> N) PRE <- <- LINK() Step 6: [Insert New_Node after given location] LINK(PRE) <- New_Node LINK(New_Node) <- Step 7: [Finished] Inserting a node before given node in the list: Take two pointer variable and PRE and initialize them with so that, and PRE point to the first node of the list ,,PRE Move and PRE until the data part of the = Value of the node before which insertion has to be done. PRE will always point to the node just before PRE Add new node in between the nodes pointed by PRE and New_Node Dept: CE DS ( ) Vishal Makwana

12 ALGORITHM: InBeforeLoc (x, First) Step : [Check for availability list underflow] If(Avail = NULL) Write( Availability stack is underflow ) Step 2: [Create node and set the data and link portion of node] ()[Remove free node from availability stack] New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to information part of node] INFO(New_Node) <- x Step 3: [Read location] Read N Step 4: [Set two pointer and PRE to First] = First PRE = Step 5: [Reach to specific location] Repeat while(info() <> N) PRE <- LINK() <- Step 6:[Insert New_Node before given Location] LINK(PRE) <- New_Node LINK(New_Node) <- Step 7: [Finished] Inserting a new node into sorted linked list Take two pointer variable and PRE and initialize them with so that, and PRE point to the first node of the list ,,PRE Move and PRE until you find the data part of a node whose value is greater than NUM. PRE will always point to the node just before. 2 Dept: CE DS ( ) Vishal Makwana

13 5 7 8 PRE Add new node in between the nodes pointed by PRE and New_Node Inserting node into sorted linked list ALGORITHM: InsOrder (x, First) Step : [Check for availability list overflow] If(Avail = NULL) Write( Availability stack is overflow ) Step 2: [Create node and set the data and link portion of node] ()[Remove free node from availability stack] New_Node <- Avail Avail <- LINK(Avail) (2)[Assign data to information part of node] INFO(New_Node) <- x Step 3: [Read location] Read N Step 4: [Set two pointer and PRE to First] = First PRE = Step 5: [Reach to specific location in ordered list] Repeat while (INFO()< N) PRE <- <- LINK() Step 6: [Insert New_Node at given location] LINK(PRE) <- New_Node LINK(New_Node) <- Step 7: [Finished] 3 Dept: CE DS ( ) Vishal Makwana

14 Deleting a first node of the linked list , Deleting a first node from given linked list ALGORITHM: DelFirst (x, First) Step : [Check for empty list] If (First = NULL) Write ( Linked list is empty and inderflow ) Step 2: [Delete first node] If (LINK(First) = NULL) Free (First) [Now list is empty] First <- NULL Step 3: [If more than one node exist] () [Assign address of first node to ] <- First (2) [Move First pointer to second node] First <- LINK() (3) [Delete node & free space] Free () Step 4: [Finished] Deleting last node of the given list: Take two pointer & PRE variables which will initially point to.,,pre Dept: CE DS ( ) Vishal Makwana

15 PRE The pointer variables will be moved to point to the last node of the linked list. So that the memory occupied by it can be freed. We also store NULL in the last node which was second to the last node initially. Deleting a last node from given linked list ALGORITHM: DelFirst (x, First) Step : [Check for empty list] If (First = NULL) Write ( Linked list is empty ) Step 2: [Assign address of first node to ] <- First Step 3: [Traverse the list till last node is reached] Repeat while (LINK() <> NULL) PRE <- <- LINK() Step 4: [Assign link of PRE to NULL which will terminates the list] LINK(PRE) <- NULL Free () Step 5: [Finished] Deleting a given node from linked list Take two pointer & PRE variables which will initially point to ,,PRE PRE The pointer variables will be moved to point to the nodes that contain NUM PRE 5 Dept: CE DS ( ) Vishal Makwana

16 7 3 9 Deleting a given node from the linked list ALGORITHM: DelLoc (x, First) Step : [Check for empty list] If (First = NULL) Write ( Linked list is empty ) Step 2: [Read position] Read N Step 3:[Assign first node address to & PRE] <- First PRE <- Step 4: [Reached at specific location] Repeat while( INFO() <> N) PRE <- <- LINK(PRE) Step 5:[Delete node & free space] LINK(PRE) <- LINK() Free () Step 6: [Finished] Searching node from given linked list, Here - > INFO =. Since -> INFO!= 5, we move to the next node Here - > INFO = 7. Since -> INFO!= 5, we move to the next node Here - > INFO = 5. Since -> INFO!= 5, POS =. POS is now stores the address of the node that contains the NUM. 6 Dept: CE DS ( ) Vishal Makwana

17 ALGORITHM: Search (x, First) Step : [Check for empty list] If(First = NULL) Then Write( List is empty & node not found ) Step 2:[Initialize] Flag <- 0 <- First Step 3: [Traverse entire list for search X] Repeat while (LINK() <> NULL) If(INFO () == X) Then Flag <- <- LINK() Else <- LINK() Step 4: [Check for node found or not] If(Flag =) Then Write( Node found ) Else Write( Node not found ) Step 5: [Finished] Count number of node in the linked list ALGORITHM: Count(First) Step : [Initialize] count <- 0 <- First Step 2: [Traverse the list until end of the list] Repeat while (LINK() <> NULL) count <- count + <- LINK() Step 3: [Display Count] Write(count) Step 4: [Finished] 7 Dept: CE DS ( ) Vishal Makwana

18 Circular Linked List The pointer of the last node contains the address of the first node this type of linked list is called Circular Linked List. Circular Linked List From above diagram, we can see that the address of last node (LINK) doesn t contain NULL value. Difference between Circular Linked List and Singly Linked List Every node is accessible from a given node that is from this given node, all nodes can be reached by chaining through the list. To delete a node from a singly linked list. It is require to have the first node s address. Such a requirement does not exist for a circular linked list. Certain operation such as splitting, concatenation becomes more efficient in the circular list. The disadvantage of a circular list is, it is possible to get into an infinite loop. In circular linked list, the detection of the end by placing a special node which can be easily identified in the circular list is called a list head. (Circular Linked List) In above figure the variable HEAD indicates the address of the list head. The INFO field of list head is not used which is shown by shading the field. This list can never be empty, so there is no need to test for empty list in circular list algorithm. An empty list is represented by having link (Head) = Head. Basic Concepts on Doubly Linked Linear Lists In Linear (Singly & Circular Linked) list structure, traversing is possible in one direction only. Sometimes, it is required to traverse the list in either direction, forward or backward. This property of linked list has two links field in a node instead of one. The links are denoted as predecessor and successor of a node. The link denoting the predecessor (Previous) of node is called left link and successor (Next) is called right link. A list containing this type of node is called doubly linked list or two way chain. L (Prev) Doubly Linked List R (Next) 8 Dept: CE DS ( ) Vishal Makwana

19 In above fig. L and R as pointers variable which represent left most node and right most node in the list. A doubly linked list as a collection of nodes, each node having three fields, ) Pointer to previous node (Pointer to Predecessor(prev)) 2) Information Field (INFO) 3) Pointer to next node (Pointer to Successor (Next)) Next INFO Previous (Node of double Linked List) Consider following variables to write an algorithm of the doubly linked list: -> It is pointer which will points to front (first) node having INFO & LINKS portion. Prev -> It is pointer which will points to previous node having INFO, Next & Prev portion. Next -> It is pointer which will points to next node having INFo, Next & Prev portion. New_Node -> It is temporary variable of node type. X -> It is the variable which will store the value/item at information part. Inserting a new node at the beginning of the Doubly Linked List 5 7 Add new node before the node. Now New_Node becomes the first node of the list Inserting new node at the beginning of the Doubly linked List Algorithm: Doubly_FInsert(, X, Next, Prev) Step : [Check for availability list under flow] if(avail = NULL) Write( Availability stack underflow ) 9 Dept: CE DS ( ) Vishal Makwana

20 Step 2: [Remove freed node availability list] New_Node <- Avail Avail <- LINK(Avail) Step 3: [Check whether any nodes exist or not in a list] (A)[If there is not any node in the list] if( = NULL) ) [Assign data to node] INFO(New_Node) <- X 2) [Set Prev & Next of node to null] Prev(New_Node) <- NULL Next(New_Node) <- NULL (B)[If there is any node available in list] ) [Assign data to node] INFO(New_Node) <- X 2) [Set Prev & Next of the new node] Prev() <- New_Node Prev(New_Node) <- NULL Next(New_Node) <- First Step 4: [Assign the address of temporary pointer to first pointer] <- New_Node Step 5: [finished] Inserting a new node at the end of the Doubly Linked List 5 7 Take a pointer variable and make it point to the first node of the list., 5 7 Move so that it points to the last node of the list. Insert new node after the node pointed by the Inserting a new node at the end of the Doubly Linked List 20 Dept: CE DS ( ) Vishal Makwana

21 Algorithm: Doubly_EInsert(, X, Next, Prev) Step : [Check for availability list underflow] if(avail = NULL) Write( Availability stack underflow ) Step 2: [Remove freed node availability list] New_Node <- Avail Avail <- LINK(Avail) Step 2: [Check whether any nodes exist or not in a list] (A)[If there is not any node in the list] if( = NULL) ) [Assign data to node] INFO(New_Node) <- X 2) [Set Prev & Next of node to null] Prev(New_Node) <- NULL Next(New_Node) <- NULL (B)[If there is any node available in list] ) [Remove freed node from availability list] New_Node <- Avail Avail <- LINK(Avail) 2) [Take temporary pointer which is point to ] <- 3) [To reach at the end of the list] Repeat while (Next()!= NULL) <- Next() 4) [Assign data to node] INFO(New_Node) <- X 5) [Set Prev & Next of the new node] Prev(New_Node) <- Next() <- New_Node Next(New_Node) <- NULL Step 3: [finished] Inserting a new node after a given node in the Doubly Linked List 5 7 Take a pointer variable and make it point to the first node of the list. 5 7, 2 Dept: CE DS ( ) Vishal Makwana

22 Inserting a New_Node after Inserting a new node after a given node in the Doubly Linked List Algorithm: Doubly_AfterLocInsert(, X, Prev, Next) Step : [Check for availability list underflow] if(avail = NULL) Write( Availability stack underflow ) Step 2: [Read location] Read NUM Step 3: [Remove freed node availability list] New_Node <- Avail Avail <- LINK(Avail) Step 4: [Set INFO part of the New_Node & Take temporary pointer which is point to ] INFO(New_Node) <- X <- Step 5: [To reach at the specific location in the list] Repeat while (INFO()!= NUM) <- Next() Step 6: [Insert New_Node after & set Prev and Next of the New_Node] Next(New_Node) <- Next () Prev(New_Node) <- Next() <- New_Node Step 7: [Finished] 22 Dept: CE DS ( ) Vishal Makwana

23 Inserting a new node before a given node in the Doubly Linked List 5 7 Take a pointer variable and make it point to the first node of the list., Move until the INFO part of = NUM before which the node has to be Inserted Inserting the new node in between the node pointed by and the node preceding it Inserting a new node before given node in the Doubly Linked List Algorithm: Doubly_BeforeLocInsert(, X, Prev, Next) Step : [Check for availability list underflow] if(avail = NULL) Write( Availability stack underflow ) Step 2: [Read location] Read NUM Step 3: [Remove freed node availability list] New_Node <- Avail Avail <- LINK(Avail) 23 Dept: CE DS ( ) Vishal Makwana

24 Step 4: [Set INFO part of the New_Node & Take temporary pointer which is point to ] INFO(New_Node) <- X <- Step 5: [To reach at the specific location in the list] Repeat while (INFO()!= NUM) <- Next() Step 6: [Insert New_Node before & set Prev and Next of the New_Node] Prev(New_Node) <- Prev () Next(New_Node) <- Step 7: [Assign Prev portion of the node whose address is next portion of the New_Node] if(prev() = NULL) <- New_Node else Next(Prev()) <- New_Node Step 7: [Finished] Deleting the first node of the Doubly Linked List Free the memory occupied by the first node of the list and the second node of the list becomes first node. 5 7 Deleting first node of the Doubly Linked List Algorithm: Doubly_FDelete(, Prev, Next) Step : [Check for empty list] if( = NULL) Write( Linked list is underflow ) Step 2: [Take temporary pointer which is point to ] <- Step 3: [Assign links so that second node becomes first node of the list] First <- Next() Prev() <- NULL Step 4: [Freed memory allocated to ] Free () 24 Dept: CE DS ( ) Vishal Makwana

25 Step 5: [Finished] Deleting the last node of the Doubly Linked List Take a pointer variable and make it point to the first node of the list , Move so that it points to the last node of the list Free the memory occupied by the node pointed by the and store NULL in it preceding node. 5 7 Deleting the last node of the Doubly Linked List Algorithm: Doubly_FDelete(, Prev, Next) Step : [Check for empty list] if( = NULL) Write( Linked list is underflow ) Step 2: [Take temporary pointer which is point to ] <- Step 3: [To reach at the end of the list] Repeat while (Next()!= NULL) <- Next() Step 3: [Assign Prev & Next of to the second last node of the list] Next(Prev()) <- NULL Step 4: [Freed memory allocated to ] Free () 25 Dept: CE DS ( ) Vishal Makwana

26 Step 5: [Finished] Deleting the node after given node in the Doubly Linked List 5 9 7, Take a pointer variable and make it point to the first node of the list Move until the INFO part of = NUM after which the node has to be Deleted Deleting the node after a given node in the Doubly Linked List Algorithm: Doubly_AfterLocDelete(, Prev, Next) Step : [Check for empty list] if( = NULL) Write( Linked list is underflow ) Step 2: [Take temporary pointer which is point to ] <- Step 3: [To reach at the specific location in the list] Repeat while (INFO()!= NUM) <- Next() Step 4: [Delete node after a node pointed by ] Temp <- Next() Next() <- Next(Temp) Prev(Next(Temp)) <- Step 4: [Freed memory allocated to Temp] Free (Temp) 26 Dept: CE DS ( ) Vishal Makwana

27 Step 5: [Finished] Advantages and Disadvantages of Linked List Advantages: A linked list use pointer & dynamic memory allocation technique, so it allocates memory at run time and save the memory space. In static memory allocation, insertion and deletion operation is very slow and complicated where using linked list it is very easy and no any shifting of memory location during insertion & deletion operations. In Circular linked list every node is accessible from the given node. Concatenation operation and splitting operation become fast in Circular linked list. We can traverse in both directions in a list using doubly linked list. Disadvantages: The disadvantage of Circular linked list is, without some care in processing, it is possible to get into infinite loop. In case of Doubly linked list, it consume more memory space compare to Singly and Circularly linked list because it has two pointer Next and Previous to hold the address of next & previous node. In linked list it is very complicated to calculate the address of any node. The searching and sorting operation become very complicated in linked list. Application of Linked List For Polynomial representation, It means in addition/subtraction /multiplication.. of two polynomials. Creation of Symbol table. In Dynamic Memory Management, it means allocation and releasing memory at runtime Representation of Sparse Matrix. Explanation of Polynomial manipulation and representation The polynomial equations are algebraic expression. The form of this expression is as below, A n x n + A n- x n- + A n-2 x n A 2 x 2 + A x + A 0 x 0 For example, 30x x 2 + 5x + where a0=, a=5, a2=20, a3=30 Where A i is Co-efficient. For above expression, four nodes are required to store the value of a0,a,a2 & a3. Each node contains three part, ) Co- efficient 2) Exponent 3) Address of next node NULL Address: Dept: CE DS ( ) Vishal Makwana

The time and space are the two measure for efficiency of an algorithm.

The time and space are the two measure for efficiency of an algorithm. There are basically six operations: 5. Sorting: Arranging the elements of list in an order (either ascending or descending). 6. Merging: combining the two list into one list. Algorithm: The time and space

More information

Insert. SEMCOM Page 1 of 11

Insert. SEMCOM Page 1 of 11 CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US02CBCA01 (Advanced C Programming and Introduction to Data Structures) *UNIT 4 (Some More Data structures

More information

Ashish Gupta, Data JUET, Guna

Ashish Gupta, Data JUET, Guna Categories of data structures Data structures are categories in two classes 1. Linear data structure: - organized into sequential fashion - elements are attached one after another - easy to implement because

More information

First of all, it is a variable, just like other variables you studied

First of all, it is a variable, just like other variables you studied Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)

More information

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables. When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called

More information

UNIT-I Fundamental Notations

UNIT-I Fundamental Notations UNIT-I Fundamental Notations Introduction to Data Structure We know that data are simply values or set of values and information is the processed data. And actually the concept of data structure is much

More information

MODULE 3: LINKED LIST

MODULE 3: LINKED LIST MODULE 3: LINKED LIST DEFINITION A linked list, or one-way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers. That is, each node is divided

More information

MODULE 5: Pointers, Preprocessor Directives and Data Structures

MODULE 5: Pointers, Preprocessor Directives and Data Structures MODULE 5: Pointers, Preprocessor Directives and Data Structures 1. What is pointer? Explain with an example program. Solution: Pointer is a variable which contains the address of another variable. Two

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

Pointers. Introduction

Pointers. Introduction Pointers Spring Semester 2007 Programming and Data Structure 1 Introduction A pointer is a variable that represents the location (rather than the value) of a data item. They have a number of useful applications.

More information

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

Chapter 2 (Dynamic variable (i.e. pointer), Static variable) Chapter 2 (Dynamic variable (i.e. pointer), Static variable) August_04 A2. Identify and explain the error in the program below. [4] #include int *pptr; void fun1() { int num; num=25; pptr= &num;

More information

MYcsvtu Notes LECTURE 34. POINTERS

MYcsvtu Notes LECTURE 34.  POINTERS LECTURE 34 POINTERS Pointer Variable Declarations and Initialization Pointer variables Contain memory addresses as their values Normal variables contain a specific value (direct reference) Pointers contain

More information

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS Contents Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS 1.1. INTRODUCTION TO COMPUTERS... 1 1.2. HISTORY OF C & C++... 3 1.3. DESIGN, DEVELOPMENT AND EXECUTION OF A PROGRAM... 3 1.4 TESTING OF PROGRAMS...

More information

UNIT IV 4 LINKED LIST

UNIT IV 4 LINKED LIST 4 UNIT IV LINKED LIST LINKED LIST SYLLABUS: 4.1 Pointers Revision 4.2 Revision of Structure 4.3 Revision of structure using pointers 4.4 Dynamic Memory Allocation 4.5 Linked list Presentation 4.6 Types

More information

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data

More information

BBM 201 DATA STRUCTURES

BBM 201 DATA STRUCTURES BBM 201 DATA STRUCTURES Lecture 8: Dynamically Allocated Linked Lists 2017-2018 Fall int x; x = 8; int A[4]; An array is stored as one contiguous block of memory. How can we add a fifth element to the

More information

[0569] p 0318 garbage

[0569] p 0318 garbage A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the

More information

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples: 1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be

More information

DC54 DATA STRUCTURES DEC 2014

DC54 DATA STRUCTURES DEC 2014 Q.2 a. Write a function that computes x^y using Recursion. The property that x^y is simply a product of x and x^(y-1 ). For example, 5^4= 5 * 5^3. The recursive definition of x^y can be represented as

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

Data Structure Series

Data Structure Series Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after

More information

Subject: Fundamental of Computer Programming 2068

Subject: Fundamental of Computer Programming 2068 Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find

More information

Cpt S 122 Data Structures. Data Structures

Cpt S 122 Data Structures. Data Structures Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation

More information

1 P age DS & OOPS / UNIT II

1 P age DS & OOPS / UNIT II UNIT II Stacks: Definition operations - applications of stack. Queues: Definition - operations Priority queues - De que Applications of queue. Linked List: Singly Linked List, Doubly Linked List, Circular

More information

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University

(13-2) Dynamic Data Structures I H&K Chapter 13. Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University (13-2) Dynamic Data Structures I H&K Chapter 13 Instructor - Andrew S. O Fallon CptS 121 (November 17, 2017) Washington State University Dynamic Data Structures (1) Structures that expand and contract

More information

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues

Lists (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues (Section 5) Lists, linked lists Implementation of lists in C Other list structures List implementation of stacks, queues, priority queues By: Pramod Parajuli, Department of Computer Science, St. Xavier

More information

IV Unit Second Part STRUCTURES

IV Unit Second Part STRUCTURES STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Pointers, Dynamic Data, and Reference Types

Pointers, Dynamic Data, and Reference Types Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple

More information

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ. C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,

More information

Variation of Pointers

Variation of Pointers Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before

More information

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Linked Lists.. and other linked structures Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Dynamic memory allocation: review typedef struct { int hitemp;

More information

CA341 - Comparative Programming Languages

CA341 - Comparative Programming Languages CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data

More information

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US02CBCA01 (Advanced C Programming and Introduction to Data Structures) *UNIT 3 (Introduction to Data

More information

Introduction to Data Structure

Introduction to Data Structure Introduction to Data Structure Introduction to Data Structure Computer is an electronic machine which is used for data processing and manipulation. When programmer collects such type of data for processing,

More information

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures

The combination of pointers, structs, and dynamic memory allocation allow for creation of data structures Data Structures in C C Programming and Software Tools N.C. State Department of Computer Science Data Structures in C The combination of pointers, structs, and dynamic memory allocation allow for creation

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

Chapter 19 Data Structures -struct -dynamic memory allocation

Chapter 19 Data Structures -struct -dynamic memory allocation Chapter 19 Data Structures -struct -dynamic memory allocation Data Structures A data structure is a particular organization of data in memory. We want to group related items together. We want to organize

More information

Advanced C Programming and Introduction to Data Structures

Advanced C Programming and Introduction to Data Structures FYBCA Semester II (Advanced C Programming and Introduction to Data Structures) Question Bank Multiple Choice Questions Unit-1 1. Which operator is used with a pointer to access the value of the variable

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

JTSK Programming in C II C-Lab II. Lecture 3 & 4

JTSK Programming in C II C-Lab II. Lecture 3 & 4 JTSK-320112 Programming in C II C-Lab II Lecture 3 & 4 Xu (Owen) He Spring 2018 Slides modified from Dr. Kinga Lipskoch Planned Syllabus The C Preprocessor Bit Operations Pointers and Arrays (Dynamically

More information

Write a C program using arrays and structure

Write a C program using arrays and structure 03 Arrays and Structutes 3.1 Arrays Declaration and initialization of one dimensional, two dimensional and character arrays, accessing array elements. (10M) 3.2 Declaration and initialization of string

More information

Pointers and File Handling

Pointers and File Handling 1 Pointers and File Handling From variables to their addresses Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 2 Basics of Pointers INDIAN INSTITUTE OF TECHNOLOGY

More information

Algorithms & Data Structures

Algorithms & Data Structures GATE- 2016-17 Postal Correspondence 1 Algorithms & Data Structures Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

Self-referential Structures and Linked List. Programming and Data Structure 1

Self-referential Structures and Linked List. Programming and Data Structure 1 Self-referential Structures and Linked List Programming and Data Structure 1 Linked List :: Basic Concepts A list refers to a set of items organized sequentially. An array is an example of a list. The

More information

Unit 7. Functions. Need of User Defined Functions

Unit 7. Functions. Need of User Defined Functions Unit 7 Functions Functions are the building blocks where every program activity occurs. They are self contained program segments that carry out some specific, well defined task. Every C program must have

More information

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.

More information

Introduction to Data Structures. Systems Programming

Introduction to Data Structures. Systems Programming Introduction to Data Structures Systems Programming Intro to Data Structures Self-referential Structures Dynamic Memory Allocation A Simple malloc Example Linear Lists Linked Lists Insertion Example Linked

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more

More information

Arrays, Pointers and Memory Management

Arrays, Pointers and Memory Management Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by

More information

Algorithms, Data Structures, and Problem Solving

Algorithms, Data Structures, and Problem Solving Algorithms, Data Structures, and Problem Solving Masoumeh Taromirad Hamlstad University DT4002, Fall 2016 Container Concepts containers store data container operations: insertion retrieval removal iteration

More information

Fundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations

Fundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations Fundamentals of Programming Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours TED (10)-3071 Reg. No.. (REVISION-2010) (Maximum marks: 100) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours PART

More information

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records

CS113: Lecture 5. Topics: Pointers. Pointers and Activation Records CS113: Lecture 5 Topics: Pointers Pointers and Activation Records 1 From Last Time: A Useless Function #include void get_age( int age ); int age; get_age( age ); printf( "Your age is: %d\n",

More information

CP2 Revision. theme: dynamic datatypes & data structures

CP2 Revision. theme: dynamic datatypes & data structures CP2 Revision theme: dynamic datatypes & data structures structs can hold any combination of datatypes handled as single entity struct { }; ;

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Programming and Data Structure Solved. MCQs- Part 2

Programming and Data Structure Solved. MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Programming and Data Structure Solved MCQs- Part 2 Unsigned integers occupies Two bytes Four bytes One byte Eight byte A weather forecasting computation

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5 1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is

More information

Chapter 19 Data Structures

Chapter 19 Data Structures Chapter 19 Data Structures Img src: reddit.com/r/programmerhumor 19-2 Data Structures A data structure is a particular organization of data in memory. We want to group related items together. We want to

More information

ECE 15B COMPUTER ORGANIZATION

ECE 15B COMPUTER ORGANIZATION ECE 15B COMPUTER ORGANIZATION Lecture 13 Strings, Lists & Stacks Announcements HW #3 Due next Friday, May 15 at 5:00 PM in HFH Project #2 Due May 29 at 5:00 PM Project #3 Assigned next Thursday, May 19

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Reg. No. : Question Paper Code : 27157

Reg. No. : Question Paper Code : 27157 WK 3 Reg. No. : Question Paper Code : 27157 B.E./B.Tech. DEGREE EXAMINATION, NOVEMBER/DECEMBER 2015. Time : Three hours Second Semester Computer Science and Engineering CS 6202 PROGRAMMING AND DATA STRUCTURES

More information

NCS 301 DATA STRUCTURE USING C

NCS 301 DATA STRUCTURE USING C NCS 301 DATA STRUCTURE USING C Unit-1 Part-4 Linked Lists Hammad Mashkoor Lari Assistant Professor Allenhouse Institute of Technology www.ncs301ds.wordpress.com Introduction List refers to linear collection

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

More information

Downloaded S. from Kiran, PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from

Downloaded S. from Kiran,  PGT (CS) KV, Malleswaram STRUCTURES. Downloaded from Downloaded S. from Kiran, www.studiestoday.com PGT (CS) KV, STRUCTURES WHAT IS A STRUCTURE? Structure is a collection of logically related data. It is also a collection of dissimilar datatype. Downloaded

More information

Language comparison. C has pointers. Java has references. C++ has pointers and references

Language comparison. C has pointers. Java has references. C++ has pointers and references Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified

More information

C Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1

C Pointers. Abdelghani Bellaachia, CSCI 1121 Page: 1 C Pointers 1. Objective... 2 2. Introduction... 2 3. Pointer Variable Declarations and Initialization... 3 4. Reference operator (&) and Dereference operator (*) 6 5. Relation between Arrays and Pointers...

More information

Outline. Computer Memory Structure Addressing Concept Introduction to Pointer Pointer Manipulation Summary

Outline. Computer Memory Structure Addressing Concept Introduction to Pointer Pointer Manipulation Summary Pointers 1 2 Outline Computer Memory Structure Addressing Concept Introduction to Pointer Pointer Manipulation Summary 3 Computer Memory Revisited Computers store data in memory slots Each slot has an

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists

Outline. Briefly review the last class Pointers and Structs Memory allocation Linked lists Outline Briefly review the last class Pointers and Structs Memory allocation Linked lists C Structures and Memory Allocation A struct is a data structure that comprises multiple types, each known as a

More information

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body;

FOR Loop. FOR Loop has three parts:initialization,condition,increment. Syntax. for(initialization;condition;increment){ body; CLASSROOM SESSION Loops in C Loops are used to repeat the execution of statement or blocks There are two types of loops 1.Entry Controlled For and While 2. Exit Controlled Do while FOR Loop FOR Loop has

More information

Data Structure with C. List

Data Structure with C. List Subject: Data Structure with C Topic: List Introduction list is a finite sequence of data items, i.e. a collection of data items arranged in a certain linear order. he basic operations performed on this

More information

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Linked-List Basic Examples A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Subsequent

More information

Database Systems II. Record Organization

Database Systems II. Record Organization Database Systems II Record Organization CMPT 454, Simon Fraser University, Fall 2009, Martin Ester 75 Introduction We have introduced secondary storage devices, in particular disks. Disks use blocks as

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. DATA STRUCUTRES A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. An algorithm, which is a finite sequence of instructions, each of which

More information

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos.

UNIT 2 ARRAYS 2.0 INTRODUCTION. Structure. Page Nos. UNIT 2 ARRAYS Arrays Structure Page Nos. 2.0 Introduction 23 2.1 Objectives 24 2.2 Arrays and Pointers 24 2.3 Sparse Matrices 25 2.4 Polynomials 28 2.5 Representation of Arrays 30 2.5.1 Row Major Representation

More information

UNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays.

UNIT-1. Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays. UNIT-1 Chapter 1(Introduction and overview) 1. Asymptotic Notations 2. One Dimensional array 3. Multi Dimensional array 4. Pointer arrays. Chapter 2 (Linked lists) 1. Definition 2. Single linked list 3.

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

Memory Allocation in C

Memory Allocation in C Memory Allocation in C When a C program is loaded into memory, it is organized into three areas of memory, called segments: the text segment, stack segment and heap segment. The text segment (also called

More information

High Performance Programming Programming in C part 1

High Performance Programming Programming in C part 1 High Performance Programming Programming in C part 1 Anastasia Kruchinina Uppsala University, Sweden April 18, 2017 HPP 1 / 53 C is designed on a way to provide a full control of the computer. C is the

More information

DECLARAING AND INITIALIZING POINTERS

DECLARAING AND INITIALIZING POINTERS DECLARAING AND INITIALIZING POINTERS Passing arguments Call by Address Introduction to Pointers Within the computer s memory, every stored data item occupies one or more contiguous memory cells (i.e.,

More information

C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming

C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming Course Overview This course transforms an IT-Professional or a Student into an expert C Programming Person with concepts

More information

Introduction to Linked Lists

Introduction to Linked Lists Introduction to Linked Lists In your previous programming course, you organized and processed data items sequentially using an array (or possibly an arraylist, or a vector). You probably performed several

More information

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming Jagannath Institute of Management Sciences Lajpat Nagar BCA II Sem C Programming UNIT I Pointers: Introduction to Pointers, Pointer Notation,Decalaration and Initialization, Accessing variable through

More information

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE Chapter 1 : What is an application of linear linked list data structures? - Quora A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements

More information

Array Initialization

Array Initialization Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]

More information

Run-time Environments - 3

Run-time Environments - 3 Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

More information

Data Structures in C. C Programming and Software Tools. N.C. State Department of Computer Science

Data Structures in C. C Programming and Software Tools. N.C. State Department of Computer Science Data Structures in C C Programming and Software Tools N.C. State Department of Computer Science Data Structures in C The combination of pointers, structs, and dynamic memory allocation allows for creation

More information

Chapter 7. Pointers. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.

Chapter 7. Pointers. Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 7 Pointers Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 7 - Pointers 7.1 Introduction 7.2 Pointer Variable Definitions and Initialization

More information

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

M.CS201 Programming language

M.CS201 Programming language Power Engineering School M.CS201 Programming language Lecture 9 Lecturer: Prof. Dr. T.Uranchimeg Agenda The char Data Type Using Character Variables Printing extended ASCII characters Arrays of Characters

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information