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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Data structure implementation with Linked lists.

Parent

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
}`
History
Why does this post require attention from curators or moderators?
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)
Post
+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?

History
Why does this post require attention from curators or moderators?
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)
https://software.codidact.com/posts/285169/285175#answer-285175 How about in this case of creating a ...
hamburgersarecool‭ wrote almost 3 years ago · edited almost 3 years ago

https://software.codidact.com/posts/285169/285175#answer-285175 How about in this case of creating a delete function? Would it be like " char delete(struct library *thislib); ", also how would I alter the the function to delete a particular book from the particular collection just by the user entering the title of the book as an input?