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.

Post History

50%
+1 −1
Q&A Data structure implementation with Linked lists.

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 ...

posted 3y ago by r~~‭

Answer
#1: Initial revision by user avatar r~~‭ · 2021-12-08T20:07:15Z (almost 3 years ago)
```c
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...)

```c
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`’.

```c
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!

```c
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!

```c
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.

```c
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?