Solved

function creation ..200 pts urgent !

Posted on 1997-12-04
2
216 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
ID: 1256503
So are you in the same class as ch4?
0
 
LVL 1

Accepted Solution

by:
yl earned 200 total points
ID: 1256504
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C: GetDiskFreeSpaceEx() for default drive 14 114
Why does module make constant click noise ? 9 135
Problem to save 10 174
Socket Programming (Unix) 8 141
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…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops 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.

860 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