Professional Documents
Culture Documents
Topics
Pointers Pointers and Arrays Pointers and Strings Pointers and Structures Structure pointer Pointers and Data Structures
Linked List Stack Queue
structure pointer
#include <stdio.h> struct card { char *face; char *suit; }; int main() { struct card aCard; struct card *cardPtr; aCard.face = "Ace"; aCard.suit = "Spades"; cardPtr = &aCard; printf( "%s%s%s\n%s%s%s\n%s%s%s\n", aCard.face, " of ", aCard.suit, cardPtr->face, " of ", cardPtr->suit, ( *cardPtr ).face, " of ", ( *cardPtr ).suit ); return 0; }
Linked Lists
A Head B C
Head: pointer to the first node The last node points to NULL
A
data pointer
A node with one data field: struct node{ int number; struct node * link;
Name
id
grdPts
next_student
name
address
phone
next
*next;
data
Pointer to the predecessor (pPre) can be in one of two states: it can contain the address of a node (i.e. you are adding somewhere after the first node in the middle or at the end) it can be NULL (i.e. you are adding either to an empty list or at the beginning of the list)
Before:
pNew pHead
Code:
pNew -> next = pHead; // set link pHead = pNew;// point list to first
to NULL node
pPre
39
Front Rear
Front Rear
Front Rear