







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An overview of lists, their data structures, implementations, and various operations such as creating, inserting, deleting, and converting strings to lists. It includes examples of list implementations using different versions of the listnode structure and dynamically created lists using malloc. The document also covers functions for empty lists, returning the first element, producing the tail of a list, and inserting and deleting elements.
Typology: Slides
1 / 47
This page cannot be seen from the preview
Don't miss anything!
List Data Structures and Operations
List Implementations
Dynamically Created Lists
Converting a String to a List
List Functions
Version 1:
#define N 1000 /* the size of the list */
typedef char LIST[N];
LIST lt; /* same as char lt[N] */
struct listnode {
char data;
struct listnode *nextptr;
typedef struct listnode
LISTNODE elem;
elem
data nextptr
a.nextptr = &b;
b.nextptr = &c;
printf("%c", a.nextptr->data);
/* 'c' printed */
printf("%c", a.nextptr->nextptr->data);
/* 'e' printed */
a b c
‘a’ ‘c’ ‘e’ NULL
/* list implementation as before */
typedef LISTNODE *LNP;
LNP head = NULL;
head = malloc(sizeof(LISTNODE));
head->data = 'n';
head->nextptr = NULL;
void *malloc(size_t size);
head
‘n’ NULL
head->nextptr->nextptr =
malloc(sizeof(LISTNODE));
head->nextptr->nextptr->data = 'w';
head->nextptr->nextptr->nextptr = NULL;
head
‘n’ ‘e’ ‘w’ NULL
#include <stdio.h>
#include <stdlib.h>
/* list type implementation */
LNP string_to_list(char []);
int main()
LNP h = NULL;
h = string_to_list("AB");
return 0;
/* implementation of string_to_list() */
head =
malloc(sizeof(LISTNODE));
head->data = s[0];
tail = head;
head
tail
tail->nextptr = malloc(sizeof(LISTNODE));
head
tail
s[2] = '\0'
/* so end of list is assigned NULL */
head
tail
continued
Make an empty list:
LNP h1;
h1 = NULL;
Test for emptiness:
int isempty(LNP sptr)
return (sptr == NULL);
char first(LNP cptr)
if (isempty(cptr))
return '\0'
else
return cptr->data;