Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

Data structure implementation with Linked lists.

+0
−3

Could someone explain this part of the coding for data structures & linked list? I actually got this code from a textbook but no matter how I read the textbook, I still don't get the concept & what it means. Thanks :")

#include<stdio.h>
#include<stdlib.h>
struct listNode{
    char data;
    struct listNode *nextPtr
};

typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

void insert(ListNodePtr *sPtr, char value);
char delete(ListNodePtr *sPtr, char value);
int isEmpty(ListNodePtr sPtr);
void printList(ListNodePtr currentPtr);
void instructions(void);

int main (void){
    //some coding
}`
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Don't typedef pointers (7 comments)
Linked list fundamentals (2 comments)

1 answer

+1
−1
struct listNode{
    char data;
    struct listNode *nextPtr
};

Computer, when I tell you that any region of memory is a struct called listNode, that means that the region of memory contains a char, which I will read from and write to using the name data. The region of memory also contains a pointer that can point to another region of memory matching the same listNode pattern; I will call this pointer nextPtr. I'll let you, computer, figure out the details of how to concretely arrange these contents inside the region.

(What's that, computer? I'm missing a semicolon? Well, okay; I guess you understood what I meant anyway, but if it'll make you happier...)

typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

Computer, I'll use the word ListNode (note the capitalization!) as an abbreviation for ‘a struct called listNode’, and I'll use the word ListNodePtr as an abbreviation for ‘a pointer to a ListNode’.

void insert(ListNodePtr *sPtr, char value);

Having told you all that, computer, now I'm going to give you a preview of what's to come. I'm going to define a function called insert that accepts a pointer to a ListNodePtr (that's a pointer to a pointer, of course!) and a char. I'm not going to tell you what that function does yet, but a human might recognize these words and imagine that the function needs to replace the ListNodePtr to which the pointer points with another ListNodePtr that itself points to a ListNode containing the char, in addition to the rest of the original list. I'll tell you all that later though, computer!

char delete(ListNodePtr *sPtr, char value);

Similarly, here's another preview of another function that accepts a pointer to a pointer and a char; this one also returns a char. Again, a human might infer, from the fact that this function accepts a pointer to a pointer, that the function needs to replace the ListNodePtr with a new one somehow—but I'll tell you that later!

int isEmpty(ListNodePtr sPtr);
void printList(ListNodePtr currentPtr);
void instructions(void);

Here are some more previews, computer! That last one is a function that accepts nothing and returns nothing; how mysterious! I must be planning on doing some side effects in there, like printing some information to the screen.

int main (void){
    //some coding
}

Finally, here's what you need to actually do when this program is run. I, uh, haven't decided yet. For now, do nothing at all.

Oh yeah, those function previews I gave you? Well, since I haven't told you to use those functions, I guess I don't need to keep my promises to tell you what they do, at least for now! But if I change this program to use them, I'll have to make good on those promises, won't I?

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

https://software.codidact.com/posts/285169/285175#answer-285175 How about in this case of creating a ... (1 comment)

Sign up to answer this question »