![]() |
| | #1 |
| Registered User Join Date: Jul 2008
Posts: 16
| Abstract data types in a queue Code: struct node {Code: void enqueue(queue* q, void* item)
{ |
| sa125 is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| You could add another parameter to specify the size of the data.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| * Join Date: Jun 2008
Posts: 108
| Do you need memcpy? Couldn't you just set new_node->data = item? I am actually working on the same thing as you right now. And that is the approach I am taking. |
| noops is offline | |
| | #4 |
| Registered User Join Date: Jul 2008
Posts: 16
| I tried that but it referenced the same item in memory for all nodes. So, in my tester.c file I inserted the string "node %d" for i = 0; i < 5, and got: node 4 node 4 node 4 node 4 node 4 Which drove me crazy. So this is how I'm working around it. |
| sa125 is offline | |
| | #5 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Quote:
Code: int i, temp;
for (i = 0; i < 5; i++) {
printf("Enter number for queue: ");
scanf("%d", &temp);
enqueue(queue_ptr, &temp);
}
| |
| tabstop is offline | |
| | #6 |
| * Join Date: Jun 2008
Posts: 108
| I did have the same problem as you probably for the reason tabstop mentioned. I was reusing the same variable to add data. Alloc new memory for each piece of data that you add to the queue. |
| noops is offline | |
![]() |
| Tags |
| adt, casting, memcpy, queue |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| reading binary file with different data types | larne | C Programming | 8 | 07-29-2008 10:12 AM |
| data structure design for data aggregation | George2 | C# Programming | 0 | 05-20-2008 06:43 AM |
| Need help with ADT (abstract data types) | ortegac | C Programming | 1 | 03-30-2006 02:23 AM |
| Possible to pack smaller data types into larger ones? | Heraclitus | C Programming | 3 | 02-09-2003 03:22 PM |
| C Programming Question | TK | A Brief History of Cprogramming.com | 13 | 07-04-2002 07:11 PM |