Solved

function creation ..200 pts urgent !

Posted on 1997-12-04
2
185 Views
Last Modified: 2010-04-02
knowing

struct data { char partno[6];
              float cost;
              int quan;
            };

struct node {struct data dat;
             struct node *link;
            };

i need to create a function
delete_from_ordered_list(struct node **hd, char *part_name);

such that

pre:  hd points to the head pointer for the list.  part_name points to a string (that identifies the node to be deleted)
post:  if a node having a partno equal part_name was on the list, it has been deleted and the function returneed 1.  Otherwise, no node was deleted and the function returned a 0.

 
0
Comment
Question by:thorn120497
2 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
So are you in the same class as ch4?
0
 
LVL 1

Accepted Solution

by:
yl earned 200 total points
Comment Utility
delete_from_ordered_list(struct node **hd, char *part_name)
{
  struct node *pNode = *hd;
  strcut node *pPrevNode = NULL;
  int iFound = 0;
 
  while (pNode != NULL) {
    if (strcmp(part_name, pNode->dat.part_no) == 0) {
       iFound = 1;
       if (pPrevNode == NULL) {
          *hd = pNode->link;
          delete pNode;
          pNode = *hd;
       }
       else {
          pPrevNode->link = pNode->link;
          delete pNode;
          pNode = pPrevNode->link;
       }
    }
    else {
       pPrevNode = pNode;
       pNode = pNode->link;
    }
  }

  return (iFound);
}
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now