C
//Enter your code here
#include <stdio.h>
#include <stdlib.h>
typedef int element;
typeef structure DListNode { // Dual Connection Node Type
element data;
struct DListNode* llink;
struct DListNode* rlink;
} } DListNode;
// Initialize dual connection list
void init(DListNode* phead)
{
phead->llink = phead;
phead->rlink = phead;
}
// Output a node in a dual connection list
void print_dlist(DListNode* phead)
{
DListNode* p;
for (p = phead->rlink; p != phead; p = p->rlink) {
printf("<-| |%d| |-> ", p->data);
}
printf("\n");
}
// Insert new data to the right of the node before.
void dinsert(DListNode *before, element data)
{
DListNode *newnode = (DListNode *)malloc(sizeof(DListNode));
strcpy(newnode->data, data);
newnode->llink = before;
newnode->rlink = before->rlink;
before->rlink->llink = newnode;
before->rlink = newnode;
}
// Delete the node removed.
void ddelete(DListNode* head, DListNode* removed)
{
if (removed == head) return;
removed->llink->rlink = removed->rlink;
removed->rlink->llink = removed->llink;
free(removed);
}
// Dual Connection List Test Program
int main(void)
{
DListNode* head = (DListNode *)malloc(sizeof(DListNode));
init(head);
printf ("Additional Steps\n");
int i = 0;
for (i = 0; i < 5; i++) {
// Insert to the right of the head node
dinsert(head, i);
print_dlist(head);
}
printf("\nDelete step\n");
for (i = 0; i < 5; i++) {
print_dlist(head);
ddelete(head, head->rlink);
}
free(head);
return 0;
}
Hello, I have a question because I couldn't move on to the next step due to a code error during the assignment.
If you run the full code above, the error appears in line 31 saying incompatible implicit discrimination of built-in function 'strcpy'.
(The corresponding line inserts // new data to the right of the node before. Below.)
strcpy(newnode->data,data); should I change this?<
c data-structure
The function strcpy is declared in string.h.
You have to explicitly include it.
#include <string.h>
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.