Solved

function creation ..200 pts urgent !

Posted on 1997-12-04
2
223 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 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

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

Suggested Solutions

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

710 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