?
Solved

function creation ..200 pts urgent !

Posted on 1997-12-04
2
Medium Priority
?
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

719 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